增加完整的平台和底层支持,删除旧的OpenGL代码

This commit is contained in:
HuYingzhuo 2019-04-30 16:42:59 +08:00
parent 5a121eb5ee
commit a51f3cffd8
229 changed files with 10583 additions and 5991 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.0)
PROJECT(ULRE)
@ -14,20 +14,15 @@ check_system_bits()
check_system_version()
set_compiler_param()
set_output_directory()
IF(WIN32)
add_subdirectory(3rdpty/glfw)
include_directories(3rdpty/glfw/include)
IF(WIN32)
include_directories(${Vulkan_INCLUDE_DIRS})
SET(SPIRV_CROSS_PATH 3rdpty/SPIRV-Cross)
include_directories(${SPIRV_CROSS_PATH})
add_subdirectory(${SPIRV_CROSS_PATH})
SET(OPENGL_LIB opengl32)
ELSE()
SET(OPENGL_LIB GL)
SET(RENDER_LIBRARY xcb)
ENDIF()
SET(VULKAN_LIB ${Vulkan_LIBRARIES})
@ -38,24 +33,21 @@ add_definitions(-DMATH_AVX)
add_definitions(-DGLFW_INCLUDE_VULKAN)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/MathGeoLib/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/GLEWCore/inc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/NvTriStrip)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
add_subdirectory(3rdpty/MathGeoLib)
add_subdirectory(3rdpty/GLEWCore)
add_subdirectory(3rdpty/NvTriStrip)
add_subdirectory(src)
SET(ULRE ULRE.Base
ULRE.RenderDevice
ULRE.RenderDriver
ULRE.RenderDevice.Vulkan
ULRE.Platform
MathGeoLib
GLEWCore
glfw
${OPENGL_LIB})
${RENDER_LIBRARY}
spirv-cross-core
${Vulkan_LIBRARY})
add_subdirectory(example)

View File

@ -1,8 +1 @@
add_subdirectory(EnumRenderDevice)
add_subdirectory(OutputGLInfo)
add_subdirectory(NullWindow)
add_subdirectory(DirectGLRender)
add_subdirectory(DirectGLTexture)
add_subdirectory(TextureSampler)
add_subdirectory(Vulkan)
add_subdirectory(Vulkan)

View File

@ -1,3 +0,0 @@
add_executable(DirectGLRender main.cpp)
target_link_libraries(DirectGLRender PRIVATE ${ULRE})

View File

@ -1,174 +0,0 @@
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderDriver.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<hgl/graph/Renderable.h>
#include<hgl/graph/RenderState.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint screen_width=1280;
constexpr uint screen_height=720;
constexpr char vertex_shader[]=R"(
#version 330 core
in vec2 Vertex;
in vec3 Color;
out vec4 FragmentColor;
void main()
{
FragmentColor=vec4(Color,1.0);
gl_Position=vec4(Vertex,0.0,1.0);
})";
constexpr char fragment_shader[]=R"(
#version 330 core
in vec4 FragmentColor;
out vec4 FragColor;
void main()
{
FragColor=vec4(FragmentColor.rgb,1);
})";
Shader shader;
bool InitShader()
{
if(!shader.AddVertexShader(vertex_shader))
return(false);
if(!shader.AddFragmentShader(fragment_shader))
return(false);
if(!shader.Build())
return(false);
if(!shader.Use())
return(false);
return(true);
}
ArrayBuffer *vb_vertex=nullptr;
ArrayBuffer *vb_color=nullptr;
VertexArray *va=nullptr;
Renderable *render_obj=nullptr;
RenderState render_state;
constexpr float vertex_data[]={0.0f,0.5f, -0.5f,-0.5f, 0.5f,-0.5f };
constexpr float color_data[]={1,0,0, 0,1,0, 0,0,1 };
constexpr GLfloat clear_color[4]=
{
77.f/255.f,
78.f/255.f,
83.f/255.f,
1.f
};
void InitRenderState()
{
DepthState *ds=new DepthState();
ds->clear_depth=true; //要求清除depth缓冲区
ds->clear_depth_value=1.0f; //depth清除所用值
ds->depth_mask=false; //关闭depth mask
ds->depth_test=false; //关闭depth test
render_state.Add(ds);
ColorState *cs=new ColorState();
cs->clear_color=true;
memcpy(cs->clear_color_value,clear_color,sizeof(GLfloat)*4);
render_state.Add(cs);
}
void InitVertexBuffer()
{
vb_vertex=CreateVBO(VB2f(3,vertex_data));
vb_color=CreateVBO(VB3f(3,color_data));
va=new VertexArray(); ///<创建VAO
const int vertex_location=shader.GetAttribLocation("Vertex"); ///<取得顶点数据输入流对应的shader地址
const int color_location=shader.GetAttribLocation("Color"); ///<取得颜色数据输入流对应的shader地址
va->SetPosition(vertex_location,vb_vertex);
va->AddBuffer(color_location,vb_color);
render_obj=new Renderable(GL_TRIANGLES,va);
}
void draw()
{
render_state.Apply();
render_obj->Draw();
}
int main(void)
{
RenderDevice *device=CreateRenderDeviceGLFW();
if(!device)
{
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
return -1;
}
if(!device->Init())
{
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
return -2;
}
WindowSetup ws;
ws.Name=U8_TEXT("Direct use \"OpenGL Core API\" Render");
RenderSetup rs;
RenderWindow *win=device->Create(screen_width,screen_height,&ws,&rs);
win->MakeToCurrent(); //切换当前窗口到前台
InitOpenGLDebug(); //初始化OpenGL调试输出
if(!InitShader())
{
std::cerr<<"init shader failed."<<std::endl;
return -3;
}
InitRenderState();
InitVertexBuffer();
win->Show();
while(win->IsOpen())
{
draw();
win->SwapBuffer(); //交换前后台显示缓冲区
win->PollEvent(); //处理窗口事件
}
delete render_obj;
delete va;
delete vb_color;
delete vb_vertex;
delete win;
delete device;
return 0;
}

View File

@ -1,4 +0,0 @@
add_executable(DirectGLTexture main.cpp TGATexture.cpp)
target_link_libraries(DirectGLTexture PRIVATE ${ULRE})

View File

@ -1,140 +0,0 @@
#include<GLEWCore/glew.h>
#include<hgl/type/DataType.h>
#include<fstream>
#include<iostream>
namespace hgl
{
namespace graph
{
namespace
{
#pragma pack(push,1)
struct TGAHeader
{
uint8 id;
uint8 color_map_type;
uint8 image_type; // 1 colormap image ,2 true-color,3 grayscale
uint16 color_map_first;
uint16 color_map_length;
uint8 color_map_size;
uint16 x_origin;
uint16 y_origin;
uint16 width;
uint16 height;
uint8 bit;
uint8 image_desc;
};
union TGAImageDesc
{
//不要把此union放到上面的struct中否则Visual C++会将此union编译成4字节。GCC无此问题
uint8 image_desc;
struct
{
uint alpha_depth:4;
uint reserved:1;
uint direction:1; //0 lower-left,1 upper left
};
};
#pragma pack(pop)
}//namespace
bool LoadTGATexture(const std::string &filename,uint &tex_id)
{
std::ifstream file;
file.open(filename,std::ifstream::in|std::ifstream::binary);
if(!file.is_open())
{
std::cerr<<"[ERROR] open file<"<<filename.c_str()<<"> failed."<<std::endl;
return(false);
}
file.seekg(0,std::ifstream::end);
const int file_length=file.tellg();
char *data=new char[file_length];
file.seekg(0,std::ifstream::beg);
file.read(data,file_length);
file.close();
TGAHeader *header=(TGAHeader *)data;
uint videomemory_format;
uint source_format;
uint line_size=0;
if(header->image_type==2)
{
if(header->bit==24)
{
videomemory_format=GL_RGB8;
source_format=GL_BGR;
line_size=header->width*3;
}
else if(header->bit==32)
{
videomemory_format=GL_RGBA8;
source_format=GL_BGRA;
line_size=header->width*4;
}
}
else if(header->image_type==3&&header->bit==8)
{
videomemory_format=GL_R8;
source_format=GL_RED;
line_size=header->width;
}
else
{
std::cerr<<"[ERROR] Image format error,filename: "<<filename.c_str()<<std::endl;
delete[] data;
return(false);
}
glCreateTextures(GL_TEXTURE_2D,1,&tex_id);
glTextureStorage2D(tex_id,1,videomemory_format,header->width,header->height);
TGAImageDesc img_desc;
img_desc.image_desc=header->image_desc;
if(img_desc.direction==1)
glTextureSubImage2D(tex_id,0,0,0,header->width,header->height,source_format,GL_UNSIGNED_BYTE,data+sizeof(TGAHeader));
else
{
char *new_img=new char[line_size*header->height];
char *sp=data+sizeof(TGAHeader)+line_size*(header->height-1);
char *tp=new_img;
for(int i=0;i<header->height;i++)
{
memcpy(tp,sp,line_size);
tp+=line_size;
sp-=line_size;
}
glTextureSubImage2D(tex_id,0,0,0,header->width,header->height,source_format,GL_UNSIGNED_BYTE,new_img);
delete[] new_img;
}
glTextureParameteri(tex_id,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTextureParameteri(tex_id,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTextureParameteri(tex_id,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTextureParameteri(tex_id,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
std::cout<<"load image file<"<<filename.c_str()<<">:<"<<header->width<<"x"<<header->height<<"> to texture ok"<<std::endl;
delete[] data;
return(true);
}
}//namespace graph
}//namespace hgl

View File

@ -1,192 +0,0 @@
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderDriver.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<hgl/graph/Renderable.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint screen_width=720;
constexpr uint screen_height=720;
uint texture_id=0;
namespace hgl
{
namespace graph
{
bool LoadTGATexture(const std::string &filename,uint &tex_id);
}
}
constexpr char vertex_shader[]=R"(
#version 330 core
in vec2 Vertex;
in vec2 TexCoord;
out vec2 FragmentTexCoord;
void main()
{
FragmentTexCoord=TexCoord;
gl_Position=vec4(Vertex,0.0,1.0);
})";
constexpr char fragment_shader[]=R"(
#version 330 core
uniform sampler2D TextureLena;
in vec2 FragmentTexCoord;
out vec4 FragColor;
void main()
{
FragColor=texture(TextureLena,FragmentTexCoord);
})";
Shader shader;
bool InitShader()
{
if(!shader.AddVertexShader(vertex_shader))
return(false);
if(!shader.AddFragmentShader(fragment_shader))
return(false);
if(!shader.Build())
return(false);
if(!shader.Use())
return(false);
return(true);
}
ArrayBuffer *vb_vertex=nullptr;
ArrayBuffer *vb_texcoord=nullptr;
VertexArray *va=nullptr;
Renderable *render_obj=nullptr;
constexpr float vertex_data[]={ -0.75f, 0.75f,
-0.75f,-0.75f,
0.75f, 0.75f,
0.75f,-0.75f
};
constexpr float texcoord_data[]={ 0,0,
0,1,
1,0,
1,1 };
void InitVertexBuffer()
{
vb_vertex=CreateVBO(VB2f(4,vertex_data));
vb_texcoord=CreateVBO(VB2f(4,texcoord_data));
va=new VertexArray();
const int vertex_location=shader.GetAttribLocation("Vertex"); ///<取得顶点数据输入流对应的shader地址
const int texcoord_location=shader.GetAttribLocation("TexCoord"); ///<取得纹理坐标数据输入流对应的shader地址
va->SetPosition(vertex_location,vb_vertex);
va->AddBuffer(texcoord_location,vb_texcoord);
render_obj=new Renderable(GL_TRIANGLE_STRIP,va);
}
bool InitTexture()
{
if(!LoadTGATexture("lena.tga",texture_id))
return(false);
int texture_location=shader.GetUniformLocation("TextureLena");
glBindTextureUnit(0,texture_id);
shader.SetUniform1i(texture_location,0);
return(true);
}
constexpr GLfloat clear_color[4]=
{
77.f/255.f,
78.f/255.f,
83.f/255.f,
1.f
};
constexpr GLfloat clear_depth=1.0f;
void draw()
{
glClearBufferfv(GL_COLOR,0,clear_color);
glClearBufferfv(GL_DEPTH,0,&clear_depth);
render_obj->Draw();
}
int main(void)
{
RenderDevice *device=CreateRenderDeviceGLFW();
if(!device)
{
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
return -1;
}
if(!device->Init())
{
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
return -2;
}
WindowSetup ws;
ws.Name=U8_TEXT("Direct use \"OpenGL Core API\" Render");
RenderSetup rs;
RenderWindow *win=device->Create(screen_width,screen_height,&ws,&rs);
win->MakeToCurrent(); //切换当前窗口到前台
InitOpenGLDebug(); //初始化OpenGL调试输出
if(!InitShader())
{
std::cerr<<"init shader failed."<<std::endl;
return -3;
}
InitVertexBuffer();
if(!InitTexture())
return -4;
win->Show();
while(win->IsOpen())
{
draw();
win->SwapBuffer(); //交换前后台显示缓冲区
win->PollEvent(); //处理窗口事件
}
delete render_obj;
delete va;
delete vb_texcoord;
delete vb_vertex;
delete win;
delete device;
return 0;
}

View File

@ -1,3 +0,0 @@
add_executable(EnumRenderDevice main.cpp)
target_link_libraries(EnumRenderDevice PRIVATE ${ULRE})

View File

@ -1,71 +0,0 @@
#include<hgl/graph/RenderDevice.h>
#include<iostream>
#include<math.h>
using namespace hgl;
void put(const struct VideoMode *vm)
{
std::cout<<"\t"<<vm->width<<"x"<<vm->height<<","<<vm->bit<<"bits,"<<vm->freq<<"hz";
}
void put(const struct Display *disp)
{
const int inch=sqrt((disp->width*disp->width)+(disp->height*disp->height))*0.03937008;
std::cout<<"["<<disp->name.c_str()<<"]["<<disp->width<<"x"<<disp->height<<" mm,"<<inch<<" inch][offset "<<disp->x<<","<<disp->y<<"]"<<std::endl;
std::cout<<"\tcurrent video mode: ";
put(disp->GetCurVideoMode());
std::cout<<std::endl;
const ObjectList<VideoMode> &vml=disp->GetVideoModeList();
for(int i=0;i<vml.GetCount();i++)
{
std::cout<<"\t"<<i<<" : ";
put(vml[i]);
std::cout<<std::endl;
}
}
int main(void)
{
RenderDevice *device=CreateRenderDeviceGLFW();
if(!device)
{
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
return -1;
}
if(!device->Init())
{
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
return -2;
}
{
const UTF8String device_name=device->GetName();
std::cout<<"RenderDevice: "<<device_name.c_str()<<std::endl;
}
List<Display *> disp_list;
device->GetDisplayList(disp_list);
const int count=disp_list.GetCount();
std::cout<<"Device have "<<count<<" display."<<std::endl;
for(int i=0;i<count;i++)
{
std::cout<<"Display "<<i<<" ";
put(GetObject(disp_list,i));
std::cout<<std::endl;
}
return 0;
}

View File

@ -1,3 +0,0 @@
add_executable(NullWindow main.cpp)
target_link_libraries(NullWindow PRIVATE ${ULRE})

View File

@ -1,50 +0,0 @@
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<GLFW/glfw3.h>
using namespace hgl;
int main(void)
{
RenderDevice *device=CreateRenderDeviceGLFW();
if(!device)
{
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
return -1;
}
if(!device->Init())
{
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
return -2;
}
WindowSetup ws;
ws.Name=U8_TEXT("Null Window");
RenderSetup rs;
RenderWindow *win=device->Create(1280,720,&ws,&rs);
win->Show();
glClearColor(0,0,0,1); //设置清屏颜色
while(win->IsOpen())
{
win->MakeToCurrent(); //切换当前窗口到前台
glClear(GL_COLOR_BUFFER_BIT); //清屏
win->SwapBuffer(); //交换前后台显示缓冲区
win->PollEvent(); //处理窗口事件
}
delete win;
delete device;
return 0;
}

View File

@ -1,5 +0,0 @@
add_executable(OutputGLInfo main.cpp)
target_link_libraries(OutputGLInfo PRIVATE ${ULRE})

View File

@ -1,110 +0,0 @@
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<string.h>
#include<GLEWCore/glew.h>
using namespace hgl;
void draw()
{
glClearColor(0,0,0,1); //设置清屏颜色
glClear(GL_COLOR_BUFFER_BIT); //清屏
}
void output_ogl_info()
{
std::cout<<"Vendor: "<<glGetString(GL_VENDOR)<<std::endl;
std::cout<<"Renderer: "<<glGetString(GL_RENDERER)<<std::endl;
std::cout<<"Version: "<<glGetString(GL_VERSION)<<std::endl;
if(!glGetStringi)
return;
GLint n=0;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
std::cout<<"Extensions:"<<std::endl;
for (GLint i=0; i<n; i++)
std::cout<<" "<<i<<" : "<<glGetStringi(GL_EXTENSIONS,i)<<std::endl;
}
void output_ogl_value(const char *name,const GLenum gl_caps)
{
GLint params;
glGetIntegerv(gl_caps, &params);
std::cout << name << ": " << params << std::endl;
}
#define OUTPUT_OGL_VALUE(name) output_ogl_value("GL_" #name,GL_##name)
void output_ogl_values()
{
OUTPUT_OGL_VALUE(MAX_VERTEX_ATTRIBS);
OUTPUT_OGL_VALUE(MAX_VERTEX_ATTRIB_BINDINGS);
OUTPUT_OGL_VALUE(MAX_TEXTURE_COORDS);
OUTPUT_OGL_VALUE(MAX_VERTEX_TEXTURE_IMAGE_UNITS); //单个顶点着色器能访问的纹理单元数
OUTPUT_OGL_VALUE(MAX_TEXTURE_IMAGE_UNITS); //单个片段着色器能访问的纹理单元数
OUTPUT_OGL_VALUE(MAX_GEOMETRY_TEXTURE_IMAGE_UNITS); //单个几何着色器能访问的纹理单元数
OUTPUT_OGL_VALUE(MAX_COMBINED_TEXTURE_IMAGE_UNITS); //所有着色器总共能访问的纹理单元数
OUTPUT_OGL_VALUE(MAX_SAMPLES);
OUTPUT_OGL_VALUE(MAX_COLOR_ATTACHMENTS);
OUTPUT_OGL_VALUE(MAX_ARRAY_TEXTURE_LAYERS);
OUTPUT_OGL_VALUE(MAX_TEXTURE_BUFFER_SIZE);
OUTPUT_OGL_VALUE(MAX_SHADER_STORAGE_BLOCK_SIZE);
OUTPUT_OGL_VALUE(MAX_VERTEX_UNIFORM_BLOCKS);
OUTPUT_OGL_VALUE(MAX_GEOMETRY_UNIFORM_BLOCKS);
OUTPUT_OGL_VALUE(MAX_FRAGMENT_UNIFORM_BLOCKS);
OUTPUT_OGL_VALUE(MAX_UNIFORM_BLOCK_SIZE);
}
int main(int argc,char **argv)
{
RenderDevice *device=CreateRenderDeviceGLFW();
if(!device)
{
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
return -1;
}
if(!device->Init())
{
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
return -2;
}
WindowSetup ws;
ws.Name=U8_TEXT("Draw Triangle");
RenderSetup rs;
if(argc>1)
{
if(stricmp(argv[1],"core")==0)
rs.opengl.core=true;
else
rs.opengl.core=false;
}
else
rs.opengl.core=false;
RenderWindow *win=device->Create(1280,720,&ws,&rs);
win->MakeToCurrent(); //切换当前窗口到前台
output_ogl_info();
output_ogl_values();
delete win;
delete device;
return 0;
}

View File

@ -1,4 +0,0 @@
add_executable(TextureSampler main.cpp TGATexture.cpp)
target_link_libraries(TextureSampler PRIVATE ${ULRE})

View File

@ -1,153 +0,0 @@
#include<GLEWCore/glew.h>
#include<hgl/type/DataType.h>
#include<fstream>
#include<iostream>
namespace hgl
{
namespace graph
{
namespace
{
#pragma pack(push,1)
struct TGAHeader
{
uint8 id;
uint8 color_map_type;
uint8 image_type; // 1 colormap image ,2 true-color,3 grayscale
uint16 color_map_first;
uint16 color_map_length;
uint8 color_map_size;
uint16 x_origin;
uint16 y_origin;
uint16 width;
uint16 height;
uint8 bit;
uint8 image_desc;
};
union TGAImageDesc
{
//不要把此union放到上面的struct中否则Visual C++会将此union编译成4字节。GCC无此问题
uint8 image_desc;
struct
{
uint alpha_depth:4;
uint reserved:1;
uint direction:1; //0 lower-left,1 upper left
};
};
#pragma pack(pop)
}//namespace
bool LoadTGATexture(const std::string &filename,GLuint &tex_id)
{
std::ifstream file;
file.open(filename,std::ifstream::in|std::ifstream::binary);
if(!file.is_open())
{
std::cerr<<"[ERROR] open file<"<<filename.c_str()<<"> failed."<<std::endl;
return(false);
}
file.seekg(0,std::ifstream::end);
const int file_length=file.tellg();
char *data=new char[file_length];
file.seekg(0,std::ifstream::beg);
file.read(data,file_length);
file.close();
TGAHeader *header=(TGAHeader *)data;
uint videomemory_format;
uint source_format;
uint line_size=0;
if(header->image_type==2)
{
if(header->bit==24)
{
videomemory_format=GL_RGB8;
source_format=GL_BGR;
line_size=header->width*3;
}
else if(header->bit==32)
{
videomemory_format=GL_RGBA8;
source_format=GL_BGRA;
line_size=header->width*4;
}
}
else if(header->image_type==3&&header->bit==8)
{
videomemory_format=GL_R8;
source_format=GL_RED;
line_size=header->width;
}
else
{
std::cerr<<"[ERROR] Image format error,filename: "<<filename.c_str()<<std::endl;
delete[] data;
return(false);
}
glCreateTextures(GL_TEXTURE_2D,1,&tex_id);
glTextureStorage2D(tex_id,1,videomemory_format,header->width,header->height);
TGAImageDesc img_desc;
img_desc.image_desc=header->image_desc;
if(img_desc.direction==1)
glTextureSubImage2D(tex_id,0,0,0,header->width,header->height,source_format,GL_UNSIGNED_BYTE,data+sizeof(TGAHeader));
else
{
char *new_img=new char[line_size*header->height];
char *sp=data+sizeof(TGAHeader)+line_size*(header->height-1);
char *tp=new_img;
for(int i=0;i<header->height;i++)
{
memcpy(tp,sp,line_size);
tp+=line_size;
sp-=line_size;
}
glTextureSubImage2D(tex_id,0,0,0,header->width,header->height,source_format,GL_UNSIGNED_BYTE,new_img);
delete[] new_img;
}
glGenerateTextureMipmap(tex_id);
std::cout<<"load image file<"<<filename.c_str()<<">:<"<<header->width<<"x"<<header->height<<"> to texture ok"<<std::endl;
delete[] data;
return(true);
}
GLuint CreateSamplerObject(GLint min_filter,GLint mag_filter,GLint clamp,const GLfloat *border_color)
{
GLuint sampler_object;
glGenSamplers(1,&sampler_object);
glSamplerParameteri(sampler_object,GL_TEXTURE_MIN_FILTER,min_filter);
glSamplerParameteri(sampler_object,GL_TEXTURE_MAG_FILTER,mag_filter);
glSamplerParameteri(sampler_object,GL_TEXTURE_WRAP_S,clamp);
glSamplerParameteri(sampler_object,GL_TEXTURE_WRAP_T,clamp);
glSamplerParameterfv(sampler_object,GL_TEXTURE_BORDER_COLOR,border_color);
return(sampler_object);
}
}//namespace graph
}//namespace hgl

View File

@ -1,200 +0,0 @@
#include<hgl/graph/RenderDevice.h>
#include<hgl/graph/RenderDriver.h>
#include<hgl/graph/RenderWindow.h>
#include<iostream>
#include<hgl/graph/Renderable.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint screen_width=640;
constexpr uint screen_height=640;
GLuint texture_id=0;
GLuint sampler_id=0;
namespace hgl
{
namespace graph
{
bool LoadTGATexture(const std::string &filename,GLuint &tex_id);
GLuint CreateSamplerObject(GLint min_filter,GLint mag_filter,GLint clamp,const GLfloat *border_color);
}
}
constexpr char vertex_shader[]=R"(
#version 330 core
in vec2 Vertex;
in vec2 TexCoord;
out vec2 FragmentTexCoord;
void main()
{
FragmentTexCoord=TexCoord;
gl_Position=vec4(Vertex,0.0,1.0);
})";
constexpr char fragment_shader[]=R"(
#version 330 core
uniform sampler2D TextureLena;
in vec2 FragmentTexCoord;
out vec4 FragColor;
void main()
{
FragColor=texture(TextureLena,FragmentTexCoord);
})";
Shader shader;
bool InitShader()
{
if(!shader.AddVertexShader(vertex_shader))
return(false);
if(!shader.AddFragmentShader(fragment_shader))
return(false);
if(!shader.Build())
return(false);
if(!shader.Use())
return(false);
return(true);
}
ArrayBuffer *vb_vertex=nullptr;
ArrayBuffer *vb_texcoord=nullptr;
VertexArray *va=nullptr;
Renderable *render_obj=nullptr;
constexpr float vertex_data[]={ -0.75f, 0.75f,
-0.75f,-0.75f,
0.75f, 0.75f,
0.75f,-0.75f
};
constexpr float texcoord_data[]={ -0.25,-0.25,
-0.25, 1.25,
1.25,-0.25,
1.25, 1.25
};
void InitVertexBuffer()
{
vb_vertex=CreateVBO(VB2f(4,vertex_data));
vb_texcoord=CreateVBO(VB2f(4,texcoord_data));
va=new VertexArray();
const int vertex_location=shader.GetAttribLocation("Vertex"); ///<取得顶点数据输入流对应的shader地址
const int texcoord_location=shader.GetAttribLocation("TexCoord"); ///<取得纹理坐标数据输入流对应的shader地址
va->SetPosition(vertex_location,vb_vertex);
va->AddBuffer(texcoord_location,vb_texcoord);
render_obj=new Renderable(GL_TRIANGLE_STRIP,va);
}
bool InitTexture()
{
if(!LoadTGATexture("lena.tga",texture_id))
return(false);
const GLfloat border_color[4]={1,1,0,1};
sampler_id=CreateSamplerObject(GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST, GL_CLAMP_TO_BORDER,border_color);
int texture_location=shader.GetUniformLocation("TextureLena");
glBindTextureUnit(0,texture_id);
glBindSampler(0,sampler_id);
shader.SetUniform1i(texture_location,0);
return(true);
}
constexpr GLfloat clear_color[4]=
{
77.f/255.f,
78.f/255.f,
83.f/255.f,
1.f
};
constexpr GLfloat clear_depth=1.0f;
void draw()
{
glClearBufferfv(GL_COLOR,0,clear_color);
glClearBufferfv(GL_DEPTH,0,&clear_depth);
render_obj->Draw();
}
int main(void)
{
RenderDevice *device=CreateRenderDeviceGLFW();
if(!device)
{
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
return -1;
}
if(!device->Init())
{
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
return -2;
}
WindowSetup ws;
ws.Name=U8_TEXT("Direct use \"OpenGL Core API\" Render");
RenderSetup rs;
RenderWindow *win=device->Create(screen_width,screen_height,&ws,&rs);
win->MakeToCurrent(); //切换当前窗口到前台
InitOpenGLDebug(); //初始化OpenGL调试输出
if(!InitShader())
{
std::cerr<<"init shader failed."<<std::endl;
return -3;
}
InitVertexBuffer();
if(!InitTexture())
return -4;
win->Show();
while(win->IsOpen())
{
draw();
win->SwapBuffer(); //交换前后台显示缓冲区
win->PollEvent(); //处理窗口事件
}
delete render_obj;
delete va;
delete vb_texcoord;
delete vb_vertex;
delete win;
delete device;
return 0;
}

View File

@ -1,24 +0,0 @@
#include<fstream>
#ifndef WIN32
#include<unistd.h>
#endif//
char *LoadFileToMemory(const char *filename,unsigned __int32 &file_length)
{
std::ifstream fs;
fs.open(filename,std::ios_base::binary);
if(!fs.is_open())
return(nullptr);
fs.seekg(0,std::ios_base::end);
file_length=fs.tellg();
char *data=new char[file_length];
fs.seekg(0,std::ios_base::beg);
fs.read(data,file_length);
fs.close();
return data;
}

View File

@ -1,6 +0,0 @@
#ifndef HGL_ASSETS_MANAGE_INCLUDE
#define HGL_ASSETS_MANAGE_INCLUDE
char *LoadFileToMemory(const char *filename,unsigned __int32 &file_length);
#endif//HGL_ASSETS_MANAGE_INCLUDE

View File

@ -1,69 +1,2 @@
IF(UNIX)
SET(RENDER_WINDOW_SOURCE XCBWindow.cpp)
SET(RENDER_WINDOW_LIBRARY xcb)
ELSEIF(WIN32)
SET(RENDER_WINDOW_SOURCE WinWindow.cpp)
ENDIF()
SET(VULKAN_TEST_SOURCE_FILES main.cpp
AssetsManage.cpp
${RENDER_WINDOW_SOURCE}
VKFormat.cpp
VKInstance.cpp
VKPhysicalDevice.cpp
VKImageView.cpp
VKCommandBuffer.cpp
VKDeviceAttribute.cpp
VKDeviceCreater.cpp
VKDevice.cpp
VKDeviceBuffer.cpp
VKBuffer.cpp
VKDescriptorSets.cpp
VKRenderPass.cpp
VKShaderModule.cpp
VKShaderModuleManage.cpp
VKVertexAttributeBinding.cpp
VKPipeline.cpp
VKSemaphore.cpp
VKFramebuffer.cpp
VKFence.cpp
VKMaterial.cpp
VKRenderable.cpp
)
SET(VULKAN_TEST_HEADER_FILES AssetsManage.h
VK.h
VKFormat.h
VKPrimivate.h
VKInstance.h
VKPhysicalDevice.h
VKImageView.h
VKCommandBuffer.h
VKSurfaceExtensionName.h
VKDeviceAttribute.h
VKDevice.h
VKBuffer.h
VKDescriptorSets.h
VKRenderPass.h
VKShaderModule.h
VKShaderModuleManage.h
VKVertexAttributeBinding.h
VKSemaphore.h
VKPipeline.h
VKFramebuffer.h
VKFence.h
VKMaterial.h
VKRenderable.h
Window.h)
SET(SHADER_FILES shader_compile.bat
FlatColor.vert
FlatColor.frag)
SOURCE_GROUP("Header Files" FILES ${VULKAN_TEST_HEADER_FILES})
SOURCE_GROUP("Source Files" FILES ${VULKAN_TEST_SOURCE_FILES})
SOURCE_GROUP("Shader Files" FILES ${SHADER_FILES})
add_executable(VulkanTest ${VULKAN_TEST_HEADER_FILES} ${VULKAN_TEST_SOURCE_FILES} ${SHADER_FILES})
target_link_libraries(VulkanTest PRIVATE ${ULRE} ${VULKAN_LIB} ${RENDER_WINDOW_LIBRARY} spirv-cross-core)
add_executable(VulkanTest main.cpp ${SHADER_FILES})
target_link_libraries(VulkanTest ${ULRE})

View File

@ -1,4 +0,0 @@
#include"Shader.h"
VK_NAMESPACE_BEGIN
VK_NAMESPACE_END

View File

@ -1,7 +0,0 @@
#ifndef HGL_GRAPH_VULKAN_SHADER_INCLUDE
#define HGL_GRAPH_VULKAN_SHADER_INCLUDE
#include"VK.h"
VK_NAMESPACE_BEGIN
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SHADER_INCLUDE

View File

@ -0,0 +1,93 @@
#pragma once
#include<hgl/platform/Window.h>
#include<hgl/graph/vulkan/VKInstance.h>
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
#include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKBuffer.h>
#include<hgl/graph/vulkan/VKShaderModule.h>
#include<hgl/graph/vulkan/VKShaderModuleManage.h>
#include<hgl/graph/vulkan/VKImageView.h>
#include<hgl/graph/vulkan/VKRenderable.h>
#include<hgl/graph/vulkan/VKDescriptorSets.h>
#include<hgl/graph/vulkan/VKRenderPass.h>
#include<hgl/graph/vulkan/VKPipeline.h>
#include<hgl/graph/vulkan/VKCommandBuffer.h>
#include<hgl/graph/vulkan/VKFormat.h>
#include<hgl/graph/vulkan/VKFramebuffer.h>
#include<hgl/graph/vulkan/VKMaterial.h>
using namespace hgl;
using namespace hgl::graph;
class VulkanApplicationFramework
{
private:
Window * win =nullptr;
vulkan::Instance * inst =nullptr;
protected:
vulkan::Device * device =nullptr;
vulkan::ShaderModuleManage *shader_manage =nullptr;
public:
virtual ~VulkanApplicationFramework()
{
SAFE_CLEAR(shader_manage);
SAFE_CLEAR(device);
SAFE_CLEAR(inst);
SAFE_CLEAR(win);
}
virtual bool Init(int w,int h)
{
win=CreateRenderWindow(OS_TEXT("VulkanTest"));
if(!win)
return(false);
if(!win->Create(w,h))
return(false);
inst=vulkan::CreateInstance(U8_TEXT("VulkanTest"));
if(!inst)
return(false);
device=inst->CreateRenderDevice(win);
if(!device)
return(false);
shader_manage=device->CreateShaderModuleManage();
const vulkan::PhysicalDevice *render_device=device->GetPhysicalDevice();
std::cout<<"auto select physical device: "<<render_device->GetDeviceName()<<std::endl;
return(true);
}
void AcquireNextFrame()
{
device->AcquireNextImage();
}
void Submit(vulkan::CommandBuffer *cmd_buf)
{
device->QueueSubmit(cmd_buf);
device->Wait();
device->QueuePresent();
}
void Wait(double seconds)
{
#ifdef WIN32
Sleep(seconds * 1000.0f);
#elif defined(__ANDROID__)
sleep(seconds);
#else
sleep(seconds);
#endif
}
};//class VulkanApplicationFramework

View File

@ -1,19 +1,4 @@
#include"Window.h"
#include"VKInstance.h"
#include"VKPhysicalDevice.h"
#include"VKDevice.h"
#include"VKBuffer.h"
#include"VKShaderModule.h"
#include"VKShaderModuleManage.h"
#include"VKImageView.h"
#include"VKRenderable.h"
#include"VKDescriptorSets.h"
#include"VKRenderPass.h"
#include"VKPipeline.h"
#include"VKCommandBuffer.h"
#include"VKFormat.h"
#include"VKFramebuffer.h"
#include"VKMaterial.h"
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
using namespace hgl;
@ -42,79 +27,6 @@ constexpr float color_data[VERTEX_COUNT][3]=
{0,0,1}
};
void wait_seconds(double seconds)
{
#ifdef WIN32
Sleep(seconds * 1000.0f);
#elif defined(__ANDROID__)
sleep(seconds);
#else
sleep(seconds);
#endif
}
class VulkanApplicationFramework
{
private:
Window * win =nullptr;
vulkan::Instance * inst =nullptr;
protected:
vulkan::Device * device =nullptr;
vulkan::ShaderModuleManage *shader_manage =nullptr;
public:
virtual ~VulkanApplicationFramework()
{
SAFE_CLEAR(shader_manage);
SAFE_CLEAR(device);
SAFE_CLEAR(inst);
SAFE_CLEAR(win);
}
virtual bool Init(int w,int h)
{
win=CreateRenderWindow(OS_TEXT("VulkanTest"));
if(!win)
return(false);
if(!win->Create(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
inst=vulkan::CreateInstance(U8_TEXT("VulkanTest"));
if(!inst)
return(false);
device=inst->CreateRenderDevice(win);
if(!device)
return(false);
shader_manage=device->CreateShaderModuleManage();
const vulkan::PhysicalDevice *render_device=device->GetPhysicalDevice();
std::cout<<"auto select physical device: "<<render_device->GetDeviceName()<<std::endl;
return(true);
}
void AcquireNextFrame()
{
device->AcquireNextImage();
}
void Submit(vulkan::CommandBuffer *cmd_buf)
{
device->QueueSubmit(cmd_buf);
device->Wait();
device->QueuePresent();
}
};//class VulkanApplicationFramework
class TestApp:public VulkanApplicationFramework
{
private: //需释放数据
@ -148,7 +60,8 @@ private:
bool InitMaterial()
{
material=shader_manage->CreateMaterial("FlatColor.vert.spv","FlatColor.frag.spv");
material=shader_manage->CreateMaterial(OS_TEXT("FlatColor.vert.spv"),
OS_TEXT("FlatColor.frag.spv"));
if(!material)
return(false);
@ -256,7 +169,7 @@ int main(int,char **)
app.AcquireNextFrame();
app.Draw();
wait_seconds(0.5);
app.Wait(0.5);
return 0;
}

133
inc/hgl/Logger.h Normal file
View File

@ -0,0 +1,133 @@
#ifndef HGL_LOGGER_INCLUDE
#define HGL_LOGGER_INCLUDE
#include<hgl/type/BaseString.h>
namespace hgl
{
namespace logger
{
enum LogLevel
{
llError=0, //错误,肯定出对话框
llProblem, //问题,默认出对话框
llHint, //提示不重要debug状态默认出对话框
llLog //记录一下
};//enum LogLevel
/**
*
*/
class Logger
{
protected:
LogLevel min_level; ///<最小输出级别
UTF16String project_code;
public:
Logger(LogLevel l){min_level=l;}
virtual ~Logger()=default;
const LogLevel GetLevel()const{return min_level;} ///<取得最小输出级别
virtual void Close()=0; ///<关闭日志
virtual void Write(const u16char *,int)=0; ///<输出一行u16char日志
virtual void Write(const char *,int)=0; ///<输出一行char(utf8)日志
};//class Logger
}//namespace logger
namespace logger
{
/**
*
*/
enum LOG_LEVEL
{
LL_START=0, ///<日志级别起始定义
LL_HOTPOT, ///<性能记录热点
LL_CODE, ///<代码日志(引擎内部记录)
LL_USER, ///<用户日志(开发人员的日志)
LL_RUN, ///<运行日志(实际使用时的日志)
LL_END ///<日志级别结束定义
};
/**
*
*/
enum AFFECTOR_LEVEL
{
AL_START=0,
AL_USER, ///<用户级(无关仅要,正常程序逻辑报错)
AL_FUNC, ///<函数级(当前函数报错)
AL_MODULE, ///<模块级
AL_FULL, ///<整体级(很严重,只能退出)
AL_MUST_FIXED, ///<必须修正的代码问题
AL_END
};
/**
*
*/
class LoggerBase
{
protected:
LOG_LEVEL log_level;
AFFECTOR_LEVEL err_level;
protected:
uint32 source_file; ///<源代所在文件ID
uint32 source_line; ///<源代码所在行
uint32 function; ///<函数ID
HGL_POINTER_UINT object_address; ///<对象地址
HGL_POINTER_UINT thread_id; ///<线程ID
public:
};//class AdvLogger
/**
* 线
*/
class ThreadLogger
{
public:
};//class ThreadLogger
/**
*
*/
class ObjectLogger
{
};
/**
*
*
*/
class TimeLogger
{
};
/**
* <br>
* 线
*/
class GraphicsLogger
{
};//
}//namespace logger
using namespace logger;
}//namespace hgl
#endif//HGL_LOGGER_INCLUDE

23
inc/hgl/Time.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef HGL_TIME_INCLUDE
#define HGL_TIME_INCLUDE
#include<hgl/type/DataType.h>
namespace hgl //时间
{
int GetTimeZone(); ///<返回时区的时差(单位:秒)
uint64 GetMilliStartTime(); ///<取得毫秒程序启动时间(单位1/1000秒)
uint64 GetMicroStartTime(); ///<取得微秒程序启动时间(单位1/1000000秒)
double GetDoubleStartTime(); ///<取得秒程序启动时间(单位:秒)
uint64 GetTime(); ///<取得当前时间(单位1/1000秒)
uint64 GetMicroTime(); ///<取得当前时间(单位1/1000000秒)
double GetDoubleTime(); ///<取得当前时间(单位:秒)
double GetLocalDoubleTime(); ///<取得本地当前时间(单位:秒)
void WaitTime(double); ///<等待一定时间(单位:秒)
}//namespace hgl
#endif//HGL_TIME_INCLUDE

View File

@ -1,4 +1,4 @@
#ifndef HGL_ENDIAN_INCLUDE
#ifndef HGL_ENDIAN_INCLUDE
#define HGL_ENDIAN_INCLUDE
#include<hgl/platform/Platform.h> // 平台定义

View File

@ -0,0 +1,75 @@
#include<hgl/filesystem/FileSystem.h>
namespace hgl
{
namespace filesystem
{
struct EnumFileConfig
{
OSString folder_name; ///<要枚举的目录名称
#if HGL_OS == HGL_OS_Windows ///<通配符过滤是Windows平台独有
OSString find_name; ///<要枚举的文件名称
#endif//HGL_OS == HGL_OS_Windows
bool proc_folder; ///<是否处理目录
bool proc_file; ///<是否处理文件
bool sub_folder; ///<是否查找子目录
public:
EnumFileConfig(const OSString &fn)
{
folder_name=fn;
#if HGL_OS == HGL_OS_Windows
find_name=OS_TEXT("*.*");
#endif//HGL_OS == HGL_OS_Windows
proc_folder=true;
proc_file=true;
sub_folder=false;
}
EnumFileConfig(const EnumFileConfig *efc,const OSString &sub_folder_name)
{
folder_name =sub_folder_name;
#if HGL_OS == HGL_OS_Windows
find_name =efc->find_name;
#endif//HGL_OS == HGL_OS_Windows
proc_folder =efc->proc_folder;
proc_file =efc->proc_file;
sub_folder =efc->sub_folder;
}
virtual ~EnumFileConfig()=default;
};//struct EnumFileConfig
/**
*
*/
class EnumFile
{
protected:
virtual void ProcFolder(struct EnumFileConfig *parent_efc,struct EnumFileConfig *cur_efc,FileInfo &fi){}
virtual void ProcFile(struct EnumFileConfig *,FileInfo &fi){}
virtual EnumFileConfig *CreateSubConfig(struct EnumFileConfig *up_efc,const FileInfo &fi)
{
const OSString full_sub_folder_name=MergeFilename(up_efc->folder_name,fi.name);
return(new EnumFileConfig(up_efc,full_sub_folder_name));
}
public:
EnumFile()=default;
virtual ~EnumFile()=default;
virtual int Enum(EnumFileConfig *);
};//class EnumFile
}//namespace filesystem
}//namespace hgl

View File

@ -0,0 +1,99 @@
#pragma once
#include<hgl/type/List.h>
namespace hgl
{
namespace filesystem
{
/**
*
*/
struct VolumeInfo
{
enum DriverType
{
dtNone=0, ///<未知类型
dtRemovable, ///<可移动设备
dtFixed, ///<固定设备
dtRemote, ///<远程设备
dtCDROM, ///<光盘驱动器
dtRamDisk, ///<内存虚拟设备
dtEnd ///<结束定义
};
u16char name[HGL_MAX_PATH]; ///<卷名称
u16char path[HGL_MAX_PATH]; ///<卷所对应的路径名(注意:不是所有卷都有对应路径)
DriverType driver_type; ///<驱动器类型(注意:不是所有的卷都对应驱动器)
uint32 serial; ///<卷序列号
u16char volume_label[HGL_MAX_PATH]; ///<卷标名称
u16char file_system[HGL_MAX_PATH]; ///<文件系统名称
uint32 filename_max_length; ///<文件名最大长度
bool unicode; ///<文件名支持UNICODE
uint64 available_space; ///<有效容量
uint64 total_space; ///<总空量
uint64 free_space; ///<自由容量
};//struct VolumeInfo
#if HGL_OS == HGL_OS_Windows
/**
*
*/
struct VolumeCheckConfig
{
bool removable =false;
bool fixed =false;
bool remote =false;
bool cdrom =false;
bool ram_disk =false;
bool unknow =false;
public:
/**
*
*/
void SetFullCheck()
{
memset(this,0xff,sizeof(VolumeCheckConfig));
}
/**
*
*/
bool isErrorConfig()const
{
if(removable)return(false);
if(fixed)return(false);
if(remote)return(false);
if(cdrom)return(false);
if(ram_disk)return(false);
if(unknow)return(false);
return(true);
}
};
/**
*
* @param vi_list
* @param check_removable
* @param check_remote
* @param check_cd
* @return -1
*/
int EnumVolume(List<VolumeInfo> &vi_list,const VolumeCheckConfig &);
#endif//HGL_OS == HGL_OS_Windows
}//namespace filesystem
}//namespace hgl

View File

@ -0,0 +1,208 @@
#ifndef HGL_FILE_SYSTEM_INCLUDE
#define HGL_FILE_SYSTEM_INCLUDE
#include<hgl/type/BaseString.h>
#include<hgl/type/List.h>
namespace hgl
{
namespace io
{
class InputStream;
}//namespace io
namespace filesystem
{
template<typename T>
inline BaseString<T> MergeFilename(const BaseString<T> &pathname,const BaseString<T> &filename,const T directory_separator_char,const T *directory_separator_str)
{
BaseString<T> fullname;
if(pathname.GetEndChar()==directory_separator_char) //结尾有分隔符
{
if(filename.GetBeginChar()==directory_separator_char) //开头有分隔符
{
fullname.Set(pathname.c_str(),pathname.Length()-1); //少取一个字符
}
else
{
fullname=pathname;
}
}
else //结尾没有分隔符
{
fullname=pathname;
if(filename.GetBeginChar()!=directory_separator_char) //开头没有分隔符
{
fullname.Strcat(directory_separator_str); //添加分隔符
}
}
fullname.Strcat(filename);
return fullname;
}
/**
*
* @param filename
* @param fullname
*/
template<typename T>
inline BaseString<T> ClipFilename(const BaseString<T> &fullname)
{
if(fullname.Length()<=1)
return(BaseString<T>());
const T spear_char[] = { '/','\\' };
const int pos=fullname.FindRightChar(spear_char);
if(pos==-1)
return BaseString<T>(fullname);
return fullname.SubString(pos+1);
}
/**
*
*/
template<typename T>
inline BaseString<T> ClipFileExtName(const BaseString<T> &fullname)
{
int end=fullname.FindChar(T('?')); //url的文件名以?为结束
if(end==-1)
end=fullname.Length();
int pos=fullname.FindRightChar(fullname.Length()-end,T('.'));
if(pos==-1)
return BaseString<T>();
return fullname.SubString(pos+1,end-(pos+1));
}
/**
*
*/
template<typename T>
inline BaseString<T> ClipLastPathname(const BaseString<T> &fullname)
{
if(fullname.Length()<=1)
return(BaseString<T>());
const T gap_char[2]={'\\','/'};
T *p=nullptr;
T *s=fullname.c_str();
T *e=fullname.c_str()+fullname.Length()-1;
while(e>s)
{
if(!p)
{
if(*e==gap_char[0]||*e==gap_char[1])
{
--e;
continue;
}
p=e;
--e;
}
else
{
if(*e==gap_char[0]||*e==gap_char[1])
{
return BaseString<T>(e+1,p-e);
}
--e;
}
}
return(BaseString<T>());
}
inline UTF8String MergeFilename(const UTF8String &pathname,const UTF8String &filename) ///<组合路径名与文件名
{return MergeFilename<char>(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_U8STR);}
inline WideString MergeFilename(const WideString &pathname,const WideString &filename) ///<组合路径名与文件名
{return MergeFilename<wchar_t>(pathname,filename,L'\\',L"\\");}
bool FileCopy(const OSString &,const OSString &); ///<文件复制
bool FileDelete(const OSString &); ///<文件删除
bool FileMove(const OSString &,const OSString &); ///<文件移动
bool FileRename(const OSString &,const OSString &); ///<文件改名
bool FileExist(const OSString &); ///<文件确认是否存在
bool FileComp(const OSString &,const OSString &); ///<文件比较
bool FileCanRead(const OSString &); ///<检测文件是否可读
bool FileCanWrite(const OSString &); ///<检测文件是否可写
bool FileCanExec(const OSString &); ///<检测文件是否可执行
int64 LoadFileToMemory(const OSString &,void **); ///<加载一个文件到内存
int64 SaveMemoryToFile(const OSString &,const void *,const int64 &); ///<保存一块内存成文件
int64 SaveMemoryToFile(const OSString &,void **,const int64 *,const int &); ///<保存多块内存成一个文件
void *LoadFileToMemory(const OSString &,int64,void *buf,int64); ///<加载一个文件的一部分到内存
bool SaveMemoryToFile(const OSString &,int64,const void *,int64); ///<保存一块内存到一个文件
bool IsDirectory(const os_char *);
inline bool IsDirectory(const OSString &str){return IsDirectory(str.c_str());} ///<判断这个名称是否是目录
#if HGL_OS != HGL_OS_Windows
bool IsLink(const os_char *); ///<判断这个名称是否是链接
#endif//
bool MakePath(const OSString &); ///<创建一个路径
bool DeletePath(const OSString &); ///<删除一个路径
void DeleteTree(const OSString &); ///<删除一个路径(包含所有文件)
bool GetCurrentPath(OSString &); ///<取得当前路径
bool GetCurrentProgram(OSString &); ///<取得当前程序全路径名称
bool GetCurrentProgramPath(OSString &); ///<取得当前程序所在路径
void GetLocalAppdataPath(os_char fn[HGL_MAX_PATH]); ///<取得当前用户应用程序数据存放路径
//使用int64而不是__int64是因为不是所有编译器都支持__int64的写法必须使用DataType.H中引入的定义
/**
*
*/
struct FileInfo ///文件信息
{
os_char name[HGL_MAX_PATH]; ///<文件名(不包含路径)
os_char fullname[HGL_MAX_PATH]; ///<完整名称(包含路径)
uint64 size; ///<文件长度
union
{
uint32 attrib; ///<文件属性
struct
{
bool is_file:1; ///<是文件
bool is_directory:1; ///<是目录
bool is_hiddle:1; ///<是否隐藏文件
#if HGL_OS != HGL_OS_Windows
bool is_link:1; ///<是否是链接
#endif//HGL_OS != HGL_OS_Windows
bool can_read:1; ///<可以读
bool can_write:1; ///<可以写
};
};
uint64 mtime; ///<最后修改日期(这个值在win/unix下不通用)
};//struct FileInfo
bool GetFileInfo(const os_char *filename,struct FileInfo &); ///<取得文件信息
int GetFileInfoList(List<FileInfo> &, const OSString &folder_name, bool proc_folder, bool proc_file, bool sub_folder);
}//namespace filesystem
}//namespace hgl
#endif//HGL_FILE_SYSTEM_INCLUDE

View File

@ -1,21 +0,0 @@
#ifndef HGL_GRAPH_BLEND_MODE_INCLUDE
#define HGL_GRAPH_BLEND_MODE_INCLUDE
namespace hgl
{
namespace graph
{
/**
*
*/
struct BlendMode ///混合模式
{
struct
{
unsigned int src,dst; ///<混合因子
unsigned int func; ///<混合方式
}rgb,alpha;
};//struct BlendMode
//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_BLEND_MODE_INCLUDE

View File

@ -1,136 +0,0 @@
#ifndef HGL_GRAPH_BUFFER_DATA_INCLUDE
#define HGL_GRAPH_BUFFER_DATA_INCLUDE
#include<GLEWCore/glew.h>
#include<hgl/type/DataType.h>
namespace hgl
{
namespace graph
{
/**
*
*/
class BufferData
{
protected:
GLsizeiptr total_bytes; ///<数据总字节数
char * buffer_data;
protected:
friend BufferData *CreateBufferData(void *data,const GLsizeiptr &length);
BufferData(char *data,const GLsizeiptr &length)
{
total_bytes =length;
buffer_data =data;
}
public:
virtual ~BufferData()=default;
GLsizeiptr GetTotalBytes ()const {return total_bytes;} ///<取得数据总字节数
void * GetData ()const {return buffer_data;} ///<取得数据指针
};//class BufferData
BufferData *CreateBufferData(const GLsizeiptr &length);
BufferData *CreateBufferData(void *data,const GLsizeiptr &length);
class VertexBufferData:public BufferData
{
GLenum data_type; ///<单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
uint data_bytes; ///<单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
uint data_comp; ///<数据成员数 (1/2/3/4如2D纹理坐标用23D坐标/法线用3)
uint data_stride; ///<每组数据字节数
GLsizeiptr data_count; ///<数据数量
protected:
friend VertexBufferData *CreateVertexBufferData(void *data,const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count);
VertexBufferData(const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count,char *data):BufferData(data,dbytes*dcm*count)
{
data_type=dt;
data_bytes=dbytes;
data_comp=dcm;
data_stride=data_comp*data_bytes;
data_count=count;
}
public:
virtual ~VertexBufferData()=default;
GLenum GetDataType ()const{return data_type;} ///<取得数据类型
uint GetComponent ()const{return data_comp;} ///<取数每一组数据中的数据数量
uint GetStride ()const{return data_stride;} ///<取得每一组数据字节数
GLsizeiptr GetCount ()const{return data_count;} ///<取得数据数量
GLsizeiptr GetTotalBytes ()const{return total_bytes;} ///<取得数据总字节数
};
/**
* <br>
*
* @param dt (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
* @param dbytes (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
* @param dcm (1/2/3/42D纹理坐标用23D坐标/线3)
* @param count
*/
VertexBufferData *CreateVertexBufferData(const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count);
/**
*
* @param data
* @param dt (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
* @param dbytes (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
* @param dcm (1/2/3/42D纹理坐标用23D坐标/线3)
* @param count
*/
VertexBufferData *CreateVertexBufferData(void *data,const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count);
#define VBDATA_CREATE_FUNC(type,gl_type,short_name) \
inline VertexBufferData *VB1##short_name(const GLsizeiptr &count){return CreateVertexBufferData(gl_type,sizeof(type),1,count);} \
inline VertexBufferData *VB2##short_name(const GLsizeiptr &count){return CreateVertexBufferData(gl_type,sizeof(type),2,count);} \
inline VertexBufferData *VB3##short_name(const GLsizeiptr &count){return CreateVertexBufferData(gl_type,sizeof(type),3,count);} \
inline VertexBufferData *VB4##short_name(const GLsizeiptr &count){return CreateVertexBufferData(gl_type,sizeof(type),4,count);} \
\
inline VertexBufferData *VB1##short_name(const GLsizeiptr &count,const type *data){return CreateVertexBufferData((void *)data,gl_type,sizeof(type),1,count);} \
inline VertexBufferData *VB2##short_name(const GLsizeiptr &count,const type *data){return CreateVertexBufferData((void *)data,gl_type,sizeof(type),2,count);} \
inline VertexBufferData *VB3##short_name(const GLsizeiptr &count,const type *data){return CreateVertexBufferData((void *)data,gl_type,sizeof(type),3,count);} \
inline VertexBufferData *VB4##short_name(const GLsizeiptr &count,const type *data){return CreateVertexBufferData((void *)data,gl_type,sizeof(type),4,count);}
VBDATA_CREATE_FUNC(int8, GL_BYTE, i8)
VBDATA_CREATE_FUNC(int8, GL_BYTE, b)
VBDATA_CREATE_FUNC(int16, GL_SHORT, i16)
VBDATA_CREATE_FUNC(int16, GL_SHORT, s)
VBDATA_CREATE_FUNC(int32, GL_INT, i32)
VBDATA_CREATE_FUNC(int32, GL_INT, i)
VBDATA_CREATE_FUNC(uint8, GL_UNSIGNED_BYTE, u8)
VBDATA_CREATE_FUNC(uint8, GL_UNSIGNED_BYTE, ub)
VBDATA_CREATE_FUNC(uint16,GL_UNSIGNED_SHORT, u16)
VBDATA_CREATE_FUNC(uint16,GL_UNSIGNED_SHORT, us)
VBDATA_CREATE_FUNC(uint32,GL_UNSIGNED_INT, u32)
VBDATA_CREATE_FUNC(uint32,GL_UNSIGNED_INT, ui)
VBDATA_CREATE_FUNC(uint16,GL_HALF_FLOAT, hf)
VBDATA_CREATE_FUNC(uint16,GL_HALF_FLOAT, f16)
VBDATA_CREATE_FUNC(float, GL_FLOAT, f)
VBDATA_CREATE_FUNC(float, GL_FLOAT, f32)
VBDATA_CREATE_FUNC(double,GL_DOUBLE, d)
VBDATA_CREATE_FUNC(double,GL_DOUBLE, f64)
#undef VBDATA_CREATE_FUNC
inline VertexBufferData *EB16(const uint16 &count){return CreateVertexBufferData(GL_UNSIGNED_SHORT, 2,1,count);}
inline VertexBufferData *EB32(const uint32 &count){return CreateVertexBufferData(GL_UNSIGNED_INT, 4,1,count);}
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_BUFFER_DATA_INCLUDE

View File

@ -1,164 +0,0 @@
#ifndef HGL_GRAPH_BUFFER_OBJECT_INCLUDE
#define HGL_GRAPH_BUFFER_OBJECT_INCLUDE
#include<hgl/graph/BufferData.h>
namespace hgl
{
namespace graph
{
/**
* <br>
* API的交接
*/
class BufferObject
{
protected:
GLuint buffer_index; ///<缓冲区索引
GLenum buffer_type; ///<缓冲区类型(GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER等)
GLenum user_pattern; ///<数据存储区使用模式(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等)
GLsizeiptr buffer_bytes;
const BufferData *buffer_data;
public:
BufferObject(GLenum type);
virtual ~BufferObject();
public:
GLuint GetBufferIndex ()const {return buffer_index;} ///<取得OpenGL缓冲区
GLenum GetBufferType ()const {return buffer_type;} ///<取得缓冲区类型
GLenum GetUserPattern ()const {return user_pattern;} ///<取得缓冲区使用方法
const BufferData *GetBufferData ()const {return buffer_data;} ///<取得缓冲数区(这里返回const是为了不想让只有BufferObject的模块可以修改数据)
const GLsizeiptr GetBufferSize ()const {return buffer_bytes;} ///<取得缓冲区总计字数
public:
bool Create (GLsizeiptr); ///<创建数据区
bool Submit (void *,GLsizeiptr,GLenum up=GL_STATIC_DRAW); ///<提交数据
bool Submit (const BufferData *,GLenum up=GL_STATIC_DRAW); ///<提交数据
bool Change (void *,GLsizeiptr,GLsizeiptr); ///<修改数据
};//class BufferObject
/**
*
*/
class VertexBufferObject:public BufferObject
{
public:
using BufferObject::BufferObject;
~VertexBufferObject()=default;
const VertexBufferData *GetVertexBufferData()const{return (const VertexBufferData *)buffer_data;}
#define VBD_FUNC_COPY(type,name) type Get##name()const{return buffer_data?((const VertexBufferData *)buffer_data)->Get##name():0;}
VBD_FUNC_COPY(GLenum,DataType)
VBD_FUNC_COPY(uint,Component)
VBD_FUNC_COPY(uint,Stride)
VBD_FUNC_COPY(GLsizeiptr,Count)
#undef VBD_FUNC_COPY
};//class VertexBufferObject:public BufferObject
/**
*
* @param buf_type (GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER等)
* @param user_pattern 使(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等)
* @param buf
*/
template<typename BO,typename BD>
inline BO *_CreateBufferObject(BD *buf=nullptr,const GLenum &user_pattern=GL_STATIC_DRAW)
{
BO *obj=new BO();
if(buf)
obj->Submit(buf,user_pattern);
return(obj);
}
///**
// * 创建一个缓冲区对象
// * @param buf_type 缓冲区类型(GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER等)
// * @param user_pattern 数据存储区使用模式(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等)
// * @param total_bytes 数据总字节数
// */
//template<typename BO>
//inline BO *_CreateBufferObject(const GLenum &buf_type,const GLenum &user_pattern,const GLsizeiptr &total_bytes)
//{
// if(total_bytes<=0)return(nullptr);
// BO *buf=new BO(buf_type);
// //if(buf->Create(total_bytes,user_pattern))
// // return buf;
// delete buf;
// return(nullptr);
//}
/**
*
* @param buf_type (GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER等)
* @param user_pattern 使(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等)
* @param total_bytes
* @param data
*/
template<typename BO>
inline BO *_CreateBufferObject(void *data,const GLsizeiptr &total_bytes,const GLenum &user_pattern=GL_STATIC_DRAW)
{
if(total_bytes<=0)return(nullptr);
if(!data)return(nullptr);
BO *buf=new BO();
//if(buf->Create(total_bytes,user_pattern))
// return buf;
if(buf->Submit(data,total_bytes,user_pattern))
return buf;
delete buf;
return(nullptr);
}
#define VBCLASS_DEF(buffer_gl_type,buffer_class_name,BASE,data_name,short_name) \
class buffer_class_name:public BASE \
{ \
public: \
\
buffer_class_name():BASE(buffer_gl_type){} \
~buffer_class_name()=default; \
}; \
\
inline buffer_class_name *Create##short_name() \
{ \
return(new buffer_class_name()); \
}; \
\
inline buffer_class_name *Create##short_name(data_name *buf=nullptr,const GLenum user_pattern=GL_STATIC_DRAW) \
{ \
return _CreateBufferObject<buffer_class_name,data_name>(buf,user_pattern); \
}; \
\
inline buffer_class_name *Create##short_name(void *data,const GLsizeiptr &size,const GLenum &user_pattern=GL_STATIC_DRAW) \
{ \
return _CreateBufferObject<buffer_class_name>(data,size,user_pattern); \
}
//ps.在这里用宏了再用模板本是多此一举但使用模板函数易于调试器中进行逐行调试同时因为INLINE编译编译器也会自动展开代码不用担心效率
VBCLASS_DEF(GL_ARRAY_BUFFER, ArrayBuffer, VertexBufferObject, VertexBufferData, VBO)
VBCLASS_DEF(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer, VertexBufferObject, VertexBufferData, EBO)
VBCLASS_DEF(GL_UNIFORM_BUFFER, UniformBuffer, BufferObject, BufferData, UBO)
VBCLASS_DEF(GL_SHADER_STORAGE_BUFFER, ShaderStorageBuffer,BufferObject, BufferData, SSBO)
#undef VBCLASS_DEF
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_BUFFER_OBJECT_INCLUDE

View File

@ -1,105 +0,0 @@
#ifndef HGL_GRAPH_MATERIAL_INCLUDE
#define HGL_GRAPH_MATERIAL_INCLUDE
#include<hgl/type/Color4f.h>
#include<hgl/graph/Shader.h>
#include<hgl/graph/Axis.h>
#include<hgl/graph/BlendMode.h>
namespace hgl
{
namespace graph
{
/**
*
* scene
* {
* mesh
* {
* Vertex
* TexCoordColor
* TexCoordNormal
* }
*
* texture
* {
* Color
* Normal
* }
* };
*
*
*
* material depth_render //只渲染深度用于shadow maps或oq等
* {
* in_vertex_attrib
* {
* Vertex
* }
*
* in_uniform
* {
* mvp
* }
* }
*
* material normal_render
* {
* in_vertex_attrib
* {
* Vertex,
* TexCoordColor,
* TexCoordNormal,
* }
*
* in_uniform
* {
* mvp
* light
* }
* }
*/
/**
*
*/
class Material
{
protected:
Shader *shader;
protected:
// Color4f Color; ///<颜色
//
//
// float alpha_test; ///<alpha测试值,0:全部不显示,1:全部显示
//
// bool outside_discard; ///<贴图出界放弃
//
// bool smooth; ///<是否平滑(未用)
//
// bool color_material; ///<是否使用颜色追踪材质
//
// bool blend; ///<是否开启混合
//
// BlendMode blend_mode; ///<混合模式
//
// Axis up_axis; ///<高度图向上轴
// struct
// {
// Color4f Emission; ///<散射光
// Color4f Ambient; ///<环境光
// Color4f Diffuse; ///<漫反射
// Color4f Specular; ///<镜面光
// float Shininess; ///<镜面指数
// }front,back;
public:
};//class Material
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_MATERIAL_INCLUDE

View File

@ -1,43 +0,0 @@
#ifndef HGL_GRAPH_PIXEL_COMPENT_INCLUDE
#define HGL_GRAPH_PIXEL_COMPENT_INCLUDE
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
/**
*
*/
enum PixelCompoment
{
HGL_PC_NONE=0,
//单通道
HGL_PC_ALPHA,
HGL_PC_DEPTH,
HGL_PC_LUMINANCE,
//2通道
HGL_PC_LUMINANCE_ALPHA,
//3通道
HGL_PC_RGB,
//4通道
HGL_PC_RGBA,
//4通道 3+1模式
HGL_PC_RGB_SPECULAR,
HGL_PC_RGB_DEPTH,
HGL_PC_NORMAL_HEIGHT,
//4通道 2+2模式
HGL_PC_RGB_NORMAL,
HGL_PC_NORMAL_TANGENT,
HGL_PC_END
};//enum PixelCompoment
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_PIXEL_COMPENT_INCLUDE

View File

@ -1,136 +0,0 @@
#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

@ -1,14 +0,0 @@
#ifndef HGL_RENDER_DRIVER_INCLUDE
#define HGL_RENDER_DRIVER_INCLUDE
#include<hgl/graph/RenderState.h>
namespace hgl
{
namespace graph
{
void InitOpenGLDebug();
bool IsSupportDSA();
}//namespace graph
}//namespace hgl
#endif//HGL_RENDER_DRIVER_INCLUDE

View File

@ -1,20 +0,0 @@
#ifndef HGL_GRAPH_RENDER_PASS_INCLUDE
#define HGL_GRAPH_RENDER_PASS_INCLUDE
namespace hgl
{
namespace graph
{
/**
*
*/
class RenderPass
{
public:
};//class RenderPass
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_PASS_INCLUDE

View File

@ -1,181 +0,0 @@
#ifndef HGL_RENDER_STATE_INCLUDE
#define HGL_RENDER_STATE_INCLUDE
#include<hgl/type/Color4f.h>
//#include<hgl/CompOperator.h>
#include<hgl/type/Set.h>
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
struct RenderStateBlock
{
/**
*
*/
virtual void Apply()=0;
/**
*
*/
virtual RenderStateBlock *CreateCopy()const=0;
};//struct RenderStateBlock
#define RSB_OBJECT_BEGIN(rs_name) struct rs_name:public RenderStateBlock \
{ \
rs_name()=default; \
rs_name(const rs_name *obj){if(!obj)memcpy(this,obj,sizeof(rs_name));} \
void Apply() override; \
RenderStateBlock *CreateCopy()const override{return(new rs_name(this));} \
\
public:
#define RSB_OBJECT_END };
RSB_OBJECT_BEGIN(ColorState)
bool red =true;
bool green =true;
bool blue =true;
bool alpha =true;
bool clear_color=false;
GLfloat clear_color_value[4]={0,0,0,0};
RSB_OBJECT_END
enum class DEPTH_TEST
{
NEVER =GL_NEVER,
LESS =GL_LESS,
EQUAL =GL_EQUAL,
LEQUAL =GL_LEQUAL,
GREATER =GL_GREATER,
NOTEQUAL =GL_NOTEQUAL,
GEQUAL =GL_GEQUAL,
ALWAYS =GL_ALWAYS,
};//enum class DEPTH_TEST_FUNC
RSB_OBJECT_BEGIN(DepthState)
GLfloat near_depth=0,
far_depth=1;
bool depth_mask=true;
GLfloat clear_depth_value=far_depth; //清空深度时所用的值
bool clear_depth; //是否要清空深度
DEPTH_TEST depth_func=DEPTH_TEST::LESS;
bool depth_test;
RSB_OBJECT_END
enum class FACE
{
FRONT =GL_FRONT,
BACK =GL_BACK,
FRONT_AND_BACK =GL_FRONT_AND_BACK,
};//enum class CULL_FACE_MODE
RSB_OBJECT_BEGIN(CullFaceState)
bool enabled =true;
FACE mode =FACE::BACK;
RSB_OBJECT_END
enum class FILL_MODE
{
POINT =GL_POINT,
LINE =GL_LINE,
FACE =GL_FILL,
};//enum class FILL_MODE
RSB_OBJECT_BEGIN(PolygonModeState)
FACE face=FACE::FRONT_AND_BACK;
FILL_MODE mode=FILL_MODE::FACE;
RSB_OBJECT_END
/**
*
*/
class RenderStateData:public RenderStateBlock
{
Set<RenderStateBlock *> state_list;
public:
RenderStateData()=default;
RenderStateData(const RenderStateData *obj)
{
operator = (obj);
}
RenderStateData(const RenderStateData &obj)
{
operator = (&obj);
}
void Add(RenderStateBlock *rsb)
{
if(!rsb)
return;
state_list.Add(rsb);
}
void Apply() override
{
const int count=state_list.GetCount();
if(count<=0)
return;
RenderStateBlock **rsb=state_list.GetData();
for(int i=0;i<count;i++)
{
(*rsb)->Apply();
++rsb;
}
}
RenderStateBlock *CreateCopy() const override
{
return(new RenderStateData(this));
}
void operator = (const RenderStateData *obj)
{
const int count=obj->state_list.GetCount();
if(count<=0)return;
RenderStateBlock **rsb=obj->state_list.GetData();
for(int i=0;i<count;i++)
{
state_list.Add((*rsb)->CreateCopy());
++rsb;
}
}
};//class RenderStateData:public RenderStateBlock
/**
*
*/
class RenderState
{
RenderStateData state_data;
public:
RenderState()=default;
RenderState(const RenderStateData &rsd):state_data(rsd){}
virtual ~RenderState()=default;
virtual void Add(RenderStateBlock *rsb) { state_data.Add(rsb); }
virtual void Apply()
{
state_data.Apply();
}
};//class RenderState
}//namespace graph
}//namespace hgl
#endif//HGL_RENDER_STATE_INCLUDE

View File

@ -1,51 +0,0 @@
#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

View File

@ -1,40 +0,0 @@
#ifndef HGL_GRAPH_RENDERABLE_INCLUDE
#define HGL_GRAPH_RENDERABLE_INCLUDE
#include<hgl/graph/VertexArray.h>
#include<hgl/graph/Shader.h>
namespace hgl
{
namespace graph
{
/**
*
*/
class Renderable
{
protected:
uint primitive; ///<绘制的图元类型
VertexArray *vao;
// Material *mtl;
public:
Renderable(uint prim,VertexArray *va=nullptr)
{
primitive=prim;
vao=va;
}
const uint GetPrimitive()const { return primitive; } ///<取得要绘制的图元类型
public:
uint GetDrawCount(); ///<取得可绘制的数据总数量
bool Draw(); ///<绘制
};//class Renderable
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDERABLE_INCLUDE

View File

@ -1,198 +0,0 @@
#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
{
namespace graph
{
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,int count,const float *);
bool SetUniform2fv(int,int count,const float *);
bool SetUniform3fv(int,int count,const float *);
bool SetUniform4fv(int,int count,const float *);
bool SetUniform2fv(int index,const Vector2f &v){return SetUniform2fv(index,1,(const float *)&v);}
bool SetUniform3fv(int index,const Vector3f &v){return SetUniform3fv(index,1,(const float *)&v);}
bool SetUniform4fv(int index,const Vector4f &v){return SetUniform4fv(index,1,(const float *)&v);}
bool SetUniform1iv(int,int count,const int *);
bool SetUniform2iv(int,int count,const int *);
bool SetUniform3iv(int,int count,const int *);
bool SetUniform4iv(int,int count,const int *);
bool SetUniform1uiv(int,int count,const unsigned int *);
bool SetUniform2uiv(int,int count,const unsigned int *);
bool SetUniform3uiv(int,int count,const unsigned int *);
bool SetUniform4uiv(int,int count,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 *,int count,const float *);
bool SetUniform2fv(const char *,int count,const float *);
bool SetUniform3fv(const char *,int count,const float *);
bool SetUniform4fv(const char *,int count,const float *);
bool SetUniform2fv(const char *name,const Vector2f &v){return SetUniform2fv(name,1,(const float *)&v);}
bool SetUniform3fv(const char *name,const Vector3f &v){return SetUniform3fv(name,1,(const float *)&v);}
bool SetUniform4fv(const char *name,const Vector4f &v){return SetUniform4fv(name,1,(const float *)&v);}
bool SetUniform1iv(const char *,int count,const int *);
bool SetUniform2iv(const char *,int count,const int *);
bool SetUniform3iv(const char *,int count,const int *);
bool SetUniform4iv(const char *,int count,const int *);
bool SetUniform1uiv(const char *,int count,const unsigned int *);
bool SetUniform2uiv(const char *,int count,const unsigned int *);
bool SetUniform3uiv(const char *,int count,const unsigned int *);
bool SetUniform4uiv(const char *,int count,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

View File

@ -1,53 +0,0 @@
#ifndef HGL_GRAPH_TEXTURE_INCLUDE
#define HGL_GRAPH_TEXTURE_INCLUDE
#include<hgl/graph/TextureData.h>
#include<hgl/type/BaseString.h>
namespace hgl
{
namespace graph
{
/**
*
*/
class Texture
{
protected:
uint type; ///<纹理类型(如GL_TEXTURE_2D类)
uint texture_id; ///<纹理ID
uint pixel_format; ///<象素格式(如RED,RG,RGB,RGBA,SRGB,SRGBA之类)
uint video_format; ///<显存格式
public:
Texture(uint t,uint tid)
{
type=t;
texture_id=tid;
pixel_format=video_format=0;
}
virtual ~Texture()
{
glDeleteTextures(1,&texture_id);
}
public:
uint GetID ()const{return texture_id;} ///<取得纹理ID
uint GetType ()const{return type;} ///<取得类型
uint GetPixelFormat ()const{return pixel_format;} ///<取得象素格式
uint GetVideoFormat ()const{return video_format;} ///<取得显存中的数据格式
public:
virtual void GenMipmaps ()=0; ///<生成mipmaps
virtual void GetMipmapLevel (int &base_level,int &max_level)=0; ///<取得贴图mipmaps级别
};//class Texture
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_TEXTURE_INCLUDE

View File

@ -1,68 +0,0 @@
#ifndef HGL_GRAPH_TEXTURE_1D_INCLUDE
#define HGL_GRAPH_TEXTURE_1D_INCLUDE
#include<hgl/graph/Texture.h>
namespace hgl
{
namespace graph
{
struct Texture1DData;
/**
* 1D贴图
*/
class Texture1D:public Texture
{
protected:
uint length;
protected:
virtual bool _SetImage (Texture1DData *)=0;
virtual int _GetImage (void *data_pointer, TSF fmt, int level)=0;
virtual bool _ChangeImage(uint s, uint l, void *data, uint bytes, TSF sf)=0;
public:
uint GetLength ()const{return length;} ///<取得纹理长度
public:
Texture1D(uint tid):Texture(GL_TEXTURE_1D,tid)
{
length=0;
}
bool SetImage (Texture1DData *); ///<创建1D贴图数据
bool SetImage (uint l, TSF fmt) ///<创建1D贴图数据
{
Texture1DData tex(l,fmt);
return SetImage(&tex);
}
bool SetImage (uint l, void *data, uint size, TSF sf, uint vf)
{
Texture1DData tex(l, data, size, sf, vf);
return SetImage(&tex);
}
bool ChangeImage (uint s,uint l,void *data,uint size,TSF sf); ///<更改1D贴图数据
int GetImage (void *data_pointer,TSF fmt,int level=0); ///<取得1D贴图数据
public:
virtual void GenMipmaps ()=0; ///<生成mipmaps
virtual void GetMipmapLevel (int &base_level,int &max_level)=0; ///<取得贴图mipmaps级别
};//class Texture1D
Texture1D *CreateTexture1D();
Texture1D *CreateTexture1D(Texture1DData *);
Texture1D *CreateTexture1D(uint length,TSF format);
Texture1D *CreateTexture1D(uint length,void *bitmap,uint bitmap_bytes,TSF source_format,uint video_format);
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_TEXTURE_1D_INCLUDE

View File

@ -1,61 +0,0 @@
#ifndef HGL_GRAPH_TEXTURE_2D_INCLUDE
#define HGL_GRAPH_TEXTURE_2D_INCLUDE
#include<hgl/graph/Texture.h>
namespace hgl
{
namespace graph
{
/**
* 2D贴图
*/
class Texture2D:public Texture
{
protected:
uint width,height; ///<宽、高
virtual bool _SetImage (Texture2DData *tex)=0;
virtual int _GetImage (void *data_pointer, TSF fmt, int level,int width,int height)=0;
virtual bool _ChangeImage(uint l, uint t, uint w, uint h, void *data, uint bytes, TSF sf)=0;
public:
uint GetWidth ()const{return width;} ///<取得纹理宽度
uint GetHeight ()const{return height;} ///<取得纹理高度
public:
Texture2D(uint tid):Texture(GL_TEXTURE_2D,tid)
{
width=height=0;
}
bool SetImage (Texture2DData *); ///<创建2D贴图数据
bool SetImage (uint w, uint h, TSF fmt)
{
Texture2DData tex(w, h, fmt);
return SetImage(&tex);
}
bool SetImage (uint w, uint h, void *data, uint size, TSF sf, uint vf)
{
Texture2DData tex(w,h,data,size,sf,vf);
return SetImage(&tex);
}
bool ChangeImage (uint l,uint t,uint w,uint h,void *,uint size, TSF sf); ///<更改贴图数据
int GetImage (void *data_pointer,TSF fmt,int level=0); ///<取得2D贴图数据
};//class Texture2D
Texture2D *CreateTexture2D();
Texture2D *CreateTexture2D(Texture2DData *);
Texture2D *CreateTexture2D(uint width,uint height,TSF format);
Texture2D *CreateTexture2D(uint width,uint height,void *bitmap,uint bitmap_bytes,TSF source_format,uint video_format);
Texture2D *CreateTexture2D(const OSString &,uint video_format=0);
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_TEXTURE_2D_INCLUDE

View File

@ -1,184 +0,0 @@
#ifndef HGL_GRAPH_TEXTURE_DATA_INCLUDE
#define HGL_GRAPH_TEXTURE_DATA_INCLUDE
#include<hgl/graph/TextureFormat.h>
namespace hgl
{
namespace graph
{
/**
*
*/
struct TextureData
{
const TextureFormat * source_format; ///<源始纹理格式
uint video_format; ///<显存格式
bool gen_mipmaps; ///<是否产生mipmaps
void * bitmap; ///<位图数据
uint bitmap_bytes; ///<位图数据字节数
public:
TextureData()=default;
virtual ~TextureData()=default;
uint GetVideoFormat()const
{
return(video_format?video_format:source_format->video_format);
}
uint GetPixelFormat()const
{
return(source_format?source_format->pixel_format:0);
}
bool SetData(size_t this_size,TSF fmt)
{
if(!TextureSourceFormatCheck(fmt))
{
hgl_zero(this,this_size);
return(false);
}
gen_mipmaps=false;
bitmap = nullptr;
bitmap_bytes = 0;
source_format = TextureFormatInfoList + fmt; //原始数据格式
video_format = source_format->video_format; //显存格式
return(true);
}
bool SetData(size_t this_size,void *data,uint size,TSF sf,uint vf)
{
if(data&&!TextureSourceFormatCheck(sf))
{
hgl_zero(this,this_size);
return(false);
}
gen_mipmaps = false;
bitmap = data;
bitmap_bytes = size;
source_format = TextureFormatInfoList + sf; //原始数据格式
video_format = vf ? vf : source_format->video_format; //显存格式
return(true);
}
};//struct TextureData
struct Texture1DData:public TextureData
{
uint length;
public:
Texture1DData()
{
hgl_zero(this, sizeof(Texture1DData));
}
Texture1DData(uint l, TSF fmt)
{
if(!SetData(sizeof(Texture1DData),fmt))return;
length = l;
}
Texture1DData(uint l, void *data, uint size, TSF sf, uint vf)
{
if(!SetData(sizeof(Texture1DData),data,size,sf,vf))return;
length=l;
}
};//struct Texture1DData:public TextureData
struct Texture2DData:public TextureData
{
uint width, height;
public:
Texture2DData()
{
hgl_zero(this, sizeof(Texture2DData));
}
Texture2DData(uint w, uint h, TSF fmt)
{
if(!SetData(sizeof(Texture2DData),fmt))return;
width = w;
height = h;
}
Texture2DData(uint w,uint h,void *data,uint size,TSF sf,uint vf)
{
if(!SetData(sizeof(Texture2DData),data,size,sf,vf))return;
width=w;
height=h;
}
};//struct Texture2DData:public TextureData
using TextureCubeMapData=Texture2DData; //cube map与2d参数一样只是数据长6倍
struct Texture1DArrayData:public TextureData
{
uint length, count;
public:
Texture1DArrayData()
{
hgl_zero(this,sizeof(Texture1DArrayData));
}
Texture1DArrayData(uint l, uint c, TSF fmt)
{
if(!SetData(sizeof(Texture1DArrayData),fmt))return;
length=l;
count=c;
}
Texture1DArrayData(uint l,uint c,void *data,uint size,TSF sf,uint vf)
{
if(!SetData(sizeof(Texture1DArrayData),data,size,sf,vf))return;
length=l;
count=c;
}
};//struct Texture1DArrayData:public TextureData
struct Texture2DArrayData:public TextureData
{
uint width, height, count;
public:
Texture2DArrayData()
{
hgl_zero(this, sizeof(Texture2DArrayData));
}
};//struct Texture2DArrayData:public TextureData
struct Texture3DData:public TextureData
{
uint width, height, depth;
public:
Texture3DData()
{
hgl_zero(this, sizeof(Texture3DData));
}
};//struct Texture3DData:public TextureData
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_TEXTURE_DATA_INCLUDE

View File

@ -1,146 +0,0 @@
#ifndef HGL_GRAPH_TEXTURE_FORMAT_INCLUDE
#define HGL_GRAPH_TEXTURE_FORMAT_INCLUDE
#include<hgl/graph/TextureSourceFormat.h>
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
//贴图类型,核心模式肯定支持array/cubemap
#define HGL_TEXTURE_1D GL_TEXTURE_1D
#define HGL_TEXTURE_2D GL_TEXTURE_2D
#define HGL_TEXTURE_3D GL_TEXTURE_3D
#define HGL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE //OpenGL 3.1
#define HGL_TEXTURE_1D_ARRAY GL_TEXTURE_1D_ARRAY
#define HGL_TEXTURE_2D_ARRAY GL_TEXTURE_2D_ARRAY //OpenGL 3.0
#define HGL_TEXTURE_CUBE_MAP GL_TEXTURE_CUBE_MAP
#define HGL_TEXTURE_CUBE_MAP_ARRAY GL_TEXTURE_CUBE_MAP_ARRAY //OpenGL 4.0
#define HGL_TEXTURE_2D_MS GL_TEXTURE_2D_MULTISAMPLE
#define HGL_TEXTURE_2D_MS_ARRAY GL_TEXTURE_2D_MULTISAMPLE_ARRAY //OpenGL 3.2
#define HGL_TEXTURE_BUFFER GL_TEXTURE_BUFFER //TBO(OpenGL 3.1)
// #define HGL_TEX_BIND_1D GL_TEXTURE_BINDING_1D
// #define HGL_TEX_BIND_2D GL_TEXTURE_BINDING_2D
// #define HGL_TEX_BIND_3D GL_TEXTURE_BINDING_3D
// #define HGL_TEX_BIND_RECTANGLE GL_TEXTURE_BINDING_RECTANGLE
// #define HGL_TEX_BIND_1D_ARRAY GL_TEXTURE_BINDING_1D_ARRAY
// #define HGL_TEX_BIND_2D_ARRAY GL_TEXTURE_BINDING_2D_ARRAY
// #define HGL_TEX_BIND_CUBE_MAP GL_TEXTURE_BINDING_CUBE_MAP
// #define HGL_TEX_BIND_CUBE_MAP_ARRAY GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
// #define HGL_TEX_BIND_2D_MS GL_TEXTURE_BINDING_2D_MULTISAMPLE
// #define HGL_TEX_BIND_2D_MS_ARRAY GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
// #define HGL_TEX_BIND_BUFFER GL_TEXTURE_BINDING_BUFFER
//采样属性
//贴图寻址模式
#define HGL_WRAP_CLAMP GL_CLAMP_TO_EDGE
#define HGL_WRAP_REPEAT GL_REPEAT
#define HGL_WRAP_MIRRORED_REPEAT GL_MIRRORED_REPEAT
//贴图过滤模式
#define HGL_FILTER_NEAREST GL_NEAREST
#define HGL_FILTER_LINEAR GL_LINEAR
#define HGL_FILTER_SMOOTH (GL_LINEAR+1) //(1.此功能为自行实现使用GL_LINEAR+1只是为了区分。2.OpenGL 4.0以下使用性能较差)
#define HGL_FILTER_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_NEAREST
#define HGL_FILTER_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST
#define HGL_FILTER_NEAREST_MIPMAP_LINEAR GL_NEAREST_MIPMAP_LINEAR
#define HGL_FILTER_LINEAR_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR
//贴图象素格式
#define HGL_DEPTH16 GL_DEPTH_COMPONENT16
#define HGL_DEPTH24 GL_DEPTH_COMPONENT24
#define HGL_DEPTH32 GL_DEPTH_COMPONENT32
#define HGL_R8 GL_R8
#define HGL_R16 GL_R16
#define HGL_RG8 GL_RG8
#define HGL_RG16 GL_RG16
#define HGL_R3_G3_B2 GL_R3_G3_B2
#define HGL_RGB4 GL_RGB4
#define HGL_RGB5 GL_RGB5
#define HGL_RGB8 GL_RGB8
#define HGL_RGB10 GL_RGB10
#define HGL_RGB12 GL_RGB12
#define HGL_RGB16 GL_RGB16
#define HGL_RGBA2 GL_RGBA2
#define HGL_RGBA4 GL_RGBA4
#define HGL_RGB5_A1 GL_RGB5_A1
#define HGL_RGBA8 GL_RGBA8
#define HGL_RGB10_A2 GL_RGB10_A2
#define HGL_RGBA12 GL_RGBA12
#define HGL_RGBA16 GL_RGBA16
#define HGL_SRGB8 GL_SRGB8
#define HGL_SRGB8_ALPHA8 GL_SRGB8_ALPHA8
#define HGL_R16F GL_R16F
#define HGL_RG16F GL_RG16F
#define HGL_RGB16F GL_RGB16F
#define HGL_RGBA16F GL_RGBA16F
#define HGL_R32F GL_R32F
#define HGL_RG32F GL_RG32F
#define HGL_RGB32F GL_RGB32F
#define HGL_RGBA32F GL_RGBA32F
#define HGL_RG11F_B10F GL_R11F_G11F_B10F
#define HGL_RGB9_E5 GL_RGB9_E5
//压缩贴图格式,核心模式无扩展,所以不用检测
#define HGL_CR GL_COMPRESSED_RED
#define HGL_CRG GL_COMPRESSED_RG
#define HGL_CRGB GL_COMPRESSED_RGB
#define HGL_CRGBA GL_COMPRESSED_RGBA
#define HGL_CSRGB GL_COMPRESSED_SRGB
#define HGL_CSRGBA GL_COMPRESSED_SRGB_ALPHA
#define HGL_DXT1RGB GL_COMPRESSED_RGB_S3TC_DXT1_EXT
#define HGL_DXT1RGBA GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
#define HGL_DXT3RGBA GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
#define HGL_DXT5RGBA GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
#define HGL_LATC1 GL_COMPRESSED_LUMINANCE_LATC1_EXT
#define HGL_LATC1s GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
#define HGL_LATC2 GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
#define HGL_LATC2s GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
#define HGL_RGTC1 GL_COMPRESSED_RED_RGTC1
#define HGL_RGTC1s GL_COMPRESSED_SIGNED_RED_RGTC1
#define HGL_RGTC2 GL_COMPRESSED_RG_RGTC2
#define HGL_RGTC2s GL_COMPRESSED_SIGNED_RG_RGTC2
#define HGL_BPTC_RGBf GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
#define HGL_BPTC_RGBuf GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
#define HGL_BPTC_RGBA GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
#define HGL_BPTC_SRGBA GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
inline const TextureFormat *GetTextureFormat(const TSF &tsf)
{
if(tsf<=HGL_SF_NONE||tsf>=HGL_SF_END)
return(nullptr);
return TextureFormatInfoList+tsf;
}
inline const uint GetVideoFormat(const TSF &tsf)
{
if (tsf <= HGL_SF_NONE || tsf >= HGL_SF_END)
return(0);
return TextureFormatInfoList[tsf].video_format;
}
inline const TextureFormat *GetTextureFormat(const char *format)
{
const TextureSourceFormat tsf= GetTextureFormatEnum(format);
if(tsf<=HGL_SF_NONE||tsf>=HGL_SF_END)
return(nullptr);
return TextureFormatInfoList+tsf;
}
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_TEXTURE_FORMAT_INCLUDE

View File

@ -1,140 +0,0 @@
#ifndef HGL_GRAPH_TEXTURE_SOURCE_FORMAT_INCLUDE
#define HGL_GRAPH_TEXTURE_SOURCE_FORMAT_INCLUDE
#include<hgl/type/DataType.h>
namespace hgl
{
namespace graph
{
/**
*
*/
enum TextureSourceFormat:uint
{
HGL_SF_NONE=0, //无用,做为枚举起始
HGL_SF_R8,
HGL_SF_RG8,
HGL_SF_RGB8,
HGL_SF_RGBA8,
HGL_SF_SRGB8,
HGL_SF_SRGBA8,
HGL_SF_R16,
HGL_SF_RG16,
HGL_SF_RGB16,
HGL_SF_RGBA16,
HGL_SF_R16F,
HGL_SF_RG16F,
HGL_SF_RGB16F,
HGL_SF_RGBA16F,
HGL_SF_R32F,
HGL_SF_RG32F,
HGL_SF_RGB32F,
HGL_SF_RGBA32F,
HGL_SF_UNCOMPRESSED, //无用,做为非压缩色分隔
HGL_SF_R3_G3_B2,
HGL_SF_RGB565,
HGL_SF_RGBA4,
HGL_SF_RGB5_A1,
HGL_SF_RGB10_A2,
HGL_SF_RG11F_B10F,
HGL_SF_RGB9_E5,
HGL_SF_DEPTH, //无用,做为深度分隔
HGL_SF_DEPTH16,
HGL_SF_DEPTH24,
HGL_SF_DEPTH32,
HGL_SF_DEPTH32F,
HGL_SF_INDEX, //无用,做为索引色分隔
HGL_SF_INDEX_16_RGB,
HGL_SF_INDEX_16_RGBA,
HGL_SF_INDEX_256_RGB,
HGL_SF_INDEX_256_RGBA,
HGL_SF_COMPRESSED, //无用,做为压缩格式分隔
//HGL_SF_CR,
//HGL_SF_CRG,
//HGL_SF_CRGB,
//HGL_SF_CRGBA,
//HGL_SF_CSRGB,
//HGL_SF_CSRGBA,
HGL_SF_DXT1RGB,
HGL_SF_DXT1RGBA,
HGL_SF_DXT3RGBA,
HGL_SF_DXT5RGBA,
HGL_SF_LATC1,
HGL_SF_LATC1s,
HGL_SF_LATC2,
HGL_SF_LATC2s,
HGL_SF_RGTC1,
HGL_SF_RGTC1s,
HGL_SF_RGTC2,
HGL_SF_RGTC2s,
HGL_SF_BPTC_RGBf,
HGL_SF_BPTC_RGBuf,
HGL_SF_BPTC_RGBA,
HGL_SF_BPTC_SRGBA,
HGL_SF_ETC2_RGB8,
HGL_SF_ETC2_SRGB8,
HGL_SF_ETC2_RGB8A1,
HGL_SF_ETC2_SRGB8A1,
HGL_SF_ETC2_RGBA8,
HGL_SF_ETC2_SRGBA8,
HGL_SF_EAC_R11,
HGL_SF_EAC_R11s,
HGL_SF_EAC_RG11,
HGL_SF_EAC_RG11s,
HGL_SF_END //无用,做为枚举结束
};//enum TextureSourceFormat
using TSF=TextureSourceFormat;
bool TextureSourceFormatCheck(const TextureSourceFormat &);
bool TextureSourceFormatDepthCheck(const TextureSourceFormat &);
struct TextureFormat
{
TextureSourceFormat tsf; //数据源格式枚举
char name[16]; //简写名称
bool compress; //是否压缩格式
uint index; //索引色数量
uint video_format; //显存格式
uint pixel_format; //象素格式(指R/RG/RGB/RGBA/DEPTH这些)
uint data_type; //数据类型(指BYTESHORTFLOAT这些)
uint source_bytes; //原始格式字节数
uint video_bytes; //显存格式字节数
};
//贴图数据源格式信息
extern const TextureFormat TextureFormatInfoList[HGL_SF_END];
TSF GetTextureFormatEnum(const char *); //根据简写名称取得对应的TextureSourceFormat
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_TEXTURE_SOURCE_FORMAT_INCLUDE

View File

@ -1,53 +0,0 @@
#ifndef HGL_GRAPH_VERTEX_ARRAY_INCLUDE
#define HGL_GRAPH_VERTEX_ARRAY_INCLUDE
#include<hgl/type/List.h>
#include<hgl/graph/BufferObject.h>
#include<hgl/graph/PixelCompoment.h>
namespace hgl
{
namespace graph
{
/**
*
*/
class VertexArray
{
protected:
GLuint vao;
List<ArrayBuffer *> vbo_list; ///<顶点数据缓冲区
ElementBuffer *element_buffer;
ArrayBuffer *position_buffer;
int position_compoment; ///<位置属性格式
public:
VertexArray();
~VertexArray();
static int GetMaxVertexAttrib();
const GLuint GetVAO ()const{return vao;} ///<取得VAO对象
public: //通用顶点缓冲区设置
int AddBuffer (int shader_location,ArrayBuffer *); ///<设置顶点缓冲区对象
ArrayBuffer * GetBuffer (int index){return GetObject(vbo_list,index);} ///<取得顶点缓冲区对象
bool ClearBuffer (int index){return vbo_list.Delete(index);} ///<清除顶点缓冲区对象
void ClearBuffers(){ vbo_list.Clear();} ///<清除所有顶点缓冲区对象
public: //特殊缓冲区独立设置函数
bool SetElement (ElementBuffer *eb); ///<设置索引缓冲区对象
bool SetPosition (int shader_location,ArrayBuffer *vb); ///<设置位置缓冲区对象
ElementBuffer * GetElement (){return element_buffer;} ///<获取索引缓冲区对象
ArrayBuffer * GetPosition (){return position_buffer;} ///<获取位置缓冲区对象
};//class VertexArray
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_VERTEX_ARRAY_INCLUDE

View File

@ -4,10 +4,10 @@
#include<hgl/type/List.h>
#include<hgl/type/BaseString.h>
#include<hgl/type/Map.h>
#include"VK.h"
#include"Window.h"
#include"VKDeviceAttribute.h"
#include"VKFramebuffer.h"
#include<hgl/platform/Window.h>
#include<hgl/graph/vulkan/VK.h>
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
#include<hgl/graph/vulkan/VKFramebuffer.h>
VK_NAMESPACE_BEGIN
struct PhysicalDevice;

View File

@ -3,8 +3,8 @@
#include<hgl/type/BaseString.h>
#include<hgl/type/List.h>
#include"Window.h"
#include"VK.h"
#include<hgl/platform/Window.h>
#include<hgl/graph/vulkan/VK.h>
VK_NAMESPACE_BEGIN
struct PhysicalDevice;

View File

@ -33,7 +33,7 @@ public:
~ShaderModuleManage();
const ShaderModule *CreateShader(const VkShaderStageFlagBits shader_stage_bit,const void *spv_data,const uint32_t spv_size);
const ShaderModule *CreateShader(const VkShaderStageFlagBits shader_stage_bit,const UTF8String &filename);
const ShaderModule *CreateShader(const VkShaderStageFlagBits shader_stage_bit,const OSString &filename);
#define ADD_SHADER_FUNC(sn,vk_name) const ShaderModule *Create##sn##Shader(const void *spv_data,const uint32_t spv_size){return CreateShader(VK_SHADER_STAGE_##vk_name##_BIT,spv_data,spv_size);}
ADD_SHADER_FUNC(Vertex, VERTEX)
@ -59,7 +59,7 @@ public:
bool ReleaseShader (const ShaderModule *);
Material * CreateMaterial(const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module)const;
Material * CreateMaterial(const UTF8String &vertex_shader_filename,const UTF8String &fragment_shader_filename)
Material * CreateMaterial(const OSString &vertex_shader_filename,const OSString &fragment_shader_filename)
{
const ShaderModule *vs=CreateShader(VK_SHADER_STAGE_VERTEX_BIT,vertex_shader_filename);

View File

@ -0,0 +1,231 @@
#ifndef HGL_IO_DATA_INPUT_STREAM_INCLUDE
#define HGL_IO_DATA_INPUT_STREAM_INCLUDE
#include<hgl/io/InputStream.h>
#include<hgl/type/BaseString.h>
#include<hgl/math/Vector.h>
namespace hgl
{
namespace io
{
class InputStream;
/**
*
*/
class DataInputStream ///格式数据输入流基类
{
protected:
InputStream *in;
public:
DataInputStream(InputStream *is)
{
in=is;
}
virtual ~DataInputStream()
{
}
virtual void Use(InputStream *is)
{
in=is;
}
virtual int64 Read(void *buf,int64 size)
{
if(!buf||size<0)return(-1);
return(in?in->Read(buf,size):-1);
}
virtual int64 Peek(void *buf,int64 size)
{
if(!buf||size<0)return(-1);
return(in?in->Peek(buf,size):-1);
}
virtual int64 ReadFully(void *buf,int64 size)
{
if(!buf||size<0)return(-1);
return(in?in->ReadFully(buf,size):-1);
}
virtual int64 Seek(int64 offset,SeekOrigin so=soBegin)
{
return(in?in->Seek(offset,so):-1);
}
virtual int64 Skip(int64 size) ///<跳过指定字节不访问
{
return(in?in->Skip(size):-1);
}
virtual bool CanRestart ()const{return in?in->CanRestart():false;} ///<是否可以复位
virtual bool CanSeek ()const{return in?in->CanSeek ():false;} ///<是否可以定位
virtual bool CanSize ()const{return in?in->CanSize ():false;} ///<是否可以取得尺寸
virtual bool CanPeek ()const{return in?in->CanPeek ():false;} ///<是否可以预览数据
virtual bool Restart ()const{return in?in->Restart ():false;} ///<复位访问指针
virtual int64 Tell ()const{return in?in->Tell ():-1;} ///<返回当前访问位置
virtual int64 GetSize ()const{return in?in->GetSize ():-1;} ///<取得流长度
virtual int64 Available ()const{return in?in->Available ():-1;} ///<剩下的可以不受阻塞读取的字节数
template<typename T> bool ReadNumber(T &value);
#define STREAM_READ(type,name) virtual bool Read##name(type &value) \
{ \
return Read(value); \
} \
\
virtual int64 Read##name(type *data,const int64 count) \
{ \
if(count<=0)return(count); \
if(!data)return(-1); \
\
return ReadArrays(data,count); \
}
STREAM_READ(char, Char );
STREAM_READ(bool, Bool );
STREAM_READ(int8, Int8 );
STREAM_READ(uint8, Uint8 );
#undef STREAM_READ
#define STREAM_READ(type,name) virtual bool Read##name(type &)=0; \
virtual int64 Read##name(type *,const int64)=0;
STREAM_READ(int16, Int16 );
STREAM_READ(int32, Int32 );
STREAM_READ(int64, Int64 );
STREAM_READ(uint16, Uint16 );
STREAM_READ(uint32, Uint32 );
STREAM_READ(uint64, Uint64 );
STREAM_READ(u16char, UTF16Char);
STREAM_READ(float, Float );
STREAM_READ(double, Double );
#undef STREAM_READ
bool Read(Vector2f &vec){return ReadFloat((float *)&vec,2)==2;}
bool Read(Vector3f &vec){return ReadFloat((float *)&vec,3)==3;}
bool Read(Vector4f &vec){return ReadFloat((float *)&vec,4)==4;}
/**
* </p>
* 使
*/
template<typename T> bool Read(T &data)
{
return(ReadFully(&data,sizeof(T))==sizeof(T));
}
/**
* </p>
* 使
* @param data
* @param count
* @return
* @return <0
*/
template<typename T> int64 ReadArrays(T *data,int64 count)
{
if(count<=0)return(count);
if(!data)return(-1);
return ReadFully(data,count*sizeof(T))/sizeof(T);
}
/**
* </p>
* 使
* @param count
* @param alloc_count (-1)
* @return 使delete[]
* @return NULL
*/
template<typename T> T *ReadArrays(int64 count)
{
if(count<=0)return(nullptr);
T *data=new T[count];
if(data==0)
return(nullptr);
if(ReadArrays(data,count)!=count)
{
delete[] data;
return(nullptr);
}
return data;
}
virtual bool ReadUTF16LEChars(u16char *,uint); ///<读取utf16-le格式字符阵列到u16char *
virtual bool ReadUTF16BEChars(u16char *,uint); ///<读取utf16-be格式字符阵列到u16char *
//32bit str-length
virtual bool ReadUTF8String (char *, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF8String (UTF8String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF8String (UTF16String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF16LEString (u16char *, uint max_len=0);
virtual bool ReadUTF16BEString (u16char *, uint max_len=0);
virtual bool ReadUTF16LEString (UTF16String &, uint max_len=0); ///<读取utf16-le格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF16BEString (UTF16String &, uint max_len=0); ///<读取utf16-be格式字符串(前缀四字节的字符串字节长度)
//16bit str-length
virtual bool ReadUTF8ShortString (char *, uint max_len=0);
virtual bool ReadUTF8ShortString (UTF8String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF8ShortString (UTF16String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF16LEShortString (u16char *, uint max_len=0);
virtual bool ReadUTF16BEShortString (u16char *, uint max_len=0);
virtual bool ReadUTF16LEShortString (UTF16String &, uint max_len=0); ///<读取utf16-le格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF16BEShortString (UTF16String &, uint max_len=0); ///<读取utf16-be格式字符串(前缀四字节的字符串字节长度)
//8bit str-length
virtual bool ReadUTF8TinyString (char *, uint max_len=0);
virtual bool ReadUTF8TinyString (UTF8String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF8TinyString (UTF16String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF16LETinyString (u16char *, uint max_len=0);
virtual bool ReadUTF16BETinyString (u16char *, uint max_len=0);
virtual bool ReadUTF16LETinyString (UTF16String &, uint max_len=0); ///<读取utf16-le格式字符串(前缀四字节的字符串字节长度)
virtual bool ReadUTF16BETinyString (UTF16String &, uint max_len=0); ///<读取utf16-be格式字符串(前缀四字节的字符串字节长度)
};//class DataInputStream
template<> bool inline DataInputStream::ReadNumber<int8>(int8 &value){return ReadInt8(value);}
template<> bool inline DataInputStream::ReadNumber<uint8>(uint8 &value){return ReadUint8(value);}
#define DIS_READ_NUMBER(type,name) template<> bool inline DataInputStream::ReadNumber<type>(type &value){return Read##name(value);}
DIS_READ_NUMBER(int16, Int16 );
DIS_READ_NUMBER(int32, Int32 );
DIS_READ_NUMBER(int64, Int64 );
DIS_READ_NUMBER(uint16, Uint16 );
DIS_READ_NUMBER(uint32, Uint32 );
DIS_READ_NUMBER(uint64, Uint64 );
DIS_READ_NUMBER(u16char, UTF16Char);
DIS_READ_NUMBER(float, Float );
DIS_READ_NUMBER(double, Double );
#undef DIS_READ_NUMBER
}//namespace io
}//namespace hgl
#include<hgl/io/EndianDataInputStream.h>
#endif//HGL_IO_DATA_INPUT_STREAM_INCLUDE

View File

@ -0,0 +1,226 @@
#ifndef HGL_IO_DATA_OUTPUT_STREAM_INCLUDE
#define HGL_IO_DATA_OUTPUT_STREAM_INCLUDE
#include<hgl/io/OutputStream.h>
#include<hgl/type/BaseString.h>
#include<hgl/CodePage.h>
#include<hgl/math/Vector.h>
namespace hgl
{
namespace io
{
class OutputStream;
/**
*
*/
class DataOutputStream ///格式数据输出流基类
{
protected:
OutputStream *out;
public:
DataOutputStream(OutputStream *os)
{
out=os;
}
virtual ~DataOutputStream()
{
}
virtual void Use(OutputStream *os)
{
out=os;
}
virtual int64 Write(const void *buf,int64 size)
{
if(!buf||size<0)return(-1);
return(out?out->Write(buf,size):-1);
}
virtual int64 WriteFully(const void *buf,int64 size)
{
if(!buf||size<0)return(-1);
return(out?out->WriteFully(buf,size):-1);
}
virtual int64 Seek(int64 offset,SeekOrigin so=soBegin)
{
return(out?out->Seek(offset,so):-1);
}
virtual bool CanRestart ()const{return out?out->CanRestart ():false;} ///<是否可以复位
virtual bool CanSeek ()const{return out?out->CanSeek ():false;} ///<是否可以定位
virtual bool CanSize ()const{return out?out->CanSize ():false;} ///<是否可以取得尺寸
virtual bool Restart ()const{return out?out->Restart ():false;} ///<复位访问指针
virtual int64 Tell ()const{return out?out->Tell ():-1;} ///<返回当前访问位置
virtual int64 GetSize ()const{return out?out->GetSize ():-1;} ///<取得流长度
virtual int64 Available ()const{return out?out->Available ():-1;} ///<剩下的可以不受阻塞写入的字节数
template<typename T> bool WriteNumber(const T &value);
#define STREAM_WRITE(type,name) virtual bool Write##name(const type &value) \
{ \
return Write(value); \
} \
\
virtual int64 Write##name(const type *data,const int64 count) \
{ \
if(count<=0)return(count); \
if(!data)return(-1); \
\
return WriteArrays(data,count); \
}
STREAM_WRITE(char, Char );
STREAM_WRITE(bool, Bool );
STREAM_WRITE(int8, Int8 );
STREAM_WRITE(uint8, Uint8 );
#undef STREAM_WRITE
#define STREAM_WRITE(type,name) virtual bool Write##name(const type &)=0; \
virtual int64 Write##name(const type *,const int64)=0;
STREAM_WRITE(int16, Int16 );
STREAM_WRITE(int32, Int32 );
STREAM_WRITE(int64, Int64 );
STREAM_WRITE(uint16, Uint16 );
STREAM_WRITE(uint32, Uint32 );
STREAM_WRITE(uint64, Uint64 );
STREAM_WRITE(u16char, UTF16Char);
STREAM_WRITE(float, Float );
STREAM_WRITE(double, Double );
#undef STREAM_WRITE
bool Write(const Vector2f &vec){return WriteFloat((float *)&vec,2)==2;}
bool Write(const Vector3f &vec){return WriteFloat((float *)&vec,3)==3;}
bool Write(const Vector4f &vec){return WriteFloat((float *)&vec,4)==4;}
/**
* </p>
* 使
*/
template<typename T> bool Write(const T &data)
{
return WriteFully(&data,sizeof(T))==sizeof(T);
}
/**
* </p>
* 使
* @param data
* @param count
* @return
* @return -1
*/
template<typename T> int64 WriteArrays(const T *data,int64 count)
{
if(count<=0)return(count);
if(!data)return(-1);
return WriteFully(data,count*sizeof(T))/sizeof(T);
}
template<typename T> bool WriteUTF8Chars (const T *str,uint count); ///<按utf8格式写入字符阵列
template<typename T> bool WriteUTF16LEChars (const T *str,uint count); ///<按utf16-le格式写入字符阵列
template<typename T> bool WriteUTF16BEChars (const T *str,uint count); ///<按utf16-be格式写入字符阵列
template<typename T> bool WriteUTF8Chars (const BaseString<T> &str){return WriteUTF8Chars (str.c_str(),str.Length());}
template<typename T> bool WriteUTF16LEChars (const BaseString<T> &str){return WriteUTF16LEChars (str.c_str(),str.Length());}
template<typename T> bool WriteUTF16BEChars (const BaseString<T> &str){return WriteUTF16BEChars (str.c_str(),str.Length());}
template<typename T> bool WriteUTF8StringWithLength (const char *str,const uint length);
template<typename T> bool WriteUTF8StringWithLength (const UTF16String &str);
template<uchar C,typename T> bool WriteUTF16StringWithLength(const u16char *str,const uint len);
public:
//32 bit length
bool WriteUTF8String (const char *str,uint length); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF8String (const char *str ); ///<按utf8格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF8String (const UTF8String &str ); ///<按utf8格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF8String (const UTF16String &str ); ///<按utf8格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16LEString (const u16char *str,uint len); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16BEString (const u16char *str,uint len); ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16LEString (const UTF16String &str ); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16BEString (const UTF16String &str ); ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16LEString (const u16char *str ); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16BEString (const u16char *str ); ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16LEString (const UTF8String &str ){return WriteUTF16LEString(to_u16(str));} ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
bool WriteUTF16BEString (const UTF8String &str ){return WriteUTF16BEString(to_u16(str));} ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
//16 bit length
bool WriteUTF8ShortString (const char *str,uint length); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF8ShortString (const char *str ); ///<按utf8格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF8ShortString (const UTF8String &str ); ///<按utf8格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF8ShortString (const UTF16String &str ); ///<按utf8格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16LEShortString(const u16char *str,uint len); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16BEShortString(const u16char *str,uint len); ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16LEShortString(const UTF16String &str ); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16BEShortString(const UTF16String &str ); ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16LEShortString(const u16char *str ); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16BEShortString(const u16char *str ); ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16LEShortString(const UTF8String &str ){return WriteUTF16LEShortString(to_u16(str));} ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
bool WriteUTF16BEShortString(const UTF8String &str ){return WriteUTF16BEShortString(to_u16(str));} ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
//8 bit length
bool WriteUTF8TinyString (const char *str,uint length); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF8TinyString (const char *str ); ///<按utf8格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF8TinyString (const UTF8String &str ); ///<按utf8格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF8TinyString (const UTF16String &str ); ///<按utf8格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16LETinyString (const u16char *str,uint len); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16BETinyString (const u16char *str,uint len); ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16LETinyString (const UTF16String &str ); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16BETinyString (const UTF16String &str ); ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16LETinyString (const u16char *str ); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16BETinyString (const u16char *str ); ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16LETinyString (const UTF8String &str ){return WriteUTF16LETinyString(to_u16(str));} ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
bool WriteUTF16BETinyString (const UTF8String &str ){return WriteUTF16BETinyString(to_u16(str));} ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
};//class DataOutputStream
template<> bool inline DataOutputStream::WriteNumber<int8>(const int8 &value){return WriteInt8(value);}
template<> bool inline DataOutputStream::WriteNumber<uint8>(const uint8 &value){return WriteUint8(value);}
#define DOS_WRITE_NUMBER(type,name) template<> bool inline DataOutputStream::WriteNumber<type>(const type &value){return Write##name(value);}
DOS_WRITE_NUMBER(int16, Int16 );
DOS_WRITE_NUMBER(int32, Int32 );
DOS_WRITE_NUMBER(int64, Int64 );
DOS_WRITE_NUMBER(uint16, Uint16 );
DOS_WRITE_NUMBER(uint32, Uint32 );
DOS_WRITE_NUMBER(uint64, Uint64 );
DOS_WRITE_NUMBER(u16char, UTF16Char);
DOS_WRITE_NUMBER(float, Float );
DOS_WRITE_NUMBER(double, Double );
#undef DOS_WRITE_NUMBER
}//namespace io
}//namespace hgl
#include<hgl/io/EndianDataOutputStream.h>
#endif//HGL_IO_DATA_OUTPUT_STREAM_INCLUDEs

View File

@ -0,0 +1,100 @@
#ifndef HGL_IO_ENDIAN_DATA_INPUT_STREAM_INCLUDE
#define HGL_IO_ENDIAN_DATA_INPUT_STREAM_INCLUDE
#include<hgl/io/DataInputStream.h>
#include<hgl/endian/Endian.h>
namespace hgl
{
namespace io
{
class DirectDataInputStream:public DataInputStream
{
public:
using DataInputStream::DataInputStream;
virtual ~DirectDataInputStream()=default;
#define STREAM_DIRECT_READ(type,name) virtual bool Read##name(type &value) \
{ \
return Read(value); \
} \
\
virtual int64 Read##name(type *data,const int64 count) \
{ \
if(count<=0)return(count); \
if(!data)return(-1); \
\
return ReadArrays(data,count); \
}
STREAM_DIRECT_READ(int16, Int16 );
STREAM_DIRECT_READ(int32, Int32 );
STREAM_DIRECT_READ(int64, Int64 );
STREAM_DIRECT_READ(uint16, Uint16 );
STREAM_DIRECT_READ(uint32, Uint32 );
STREAM_DIRECT_READ(uint64, Uint64 );
STREAM_DIRECT_READ(u16char,UTF16Char);
STREAM_DIRECT_READ(float, Float );
STREAM_DIRECT_READ(double, Double );
#undef STREAM_DIRECT_READ
};//class DirectDataInputStream
class SwapDataInputStream:public DataInputStream
{
public:
using DataInputStream::DataInputStream;
virtual ~SwapDataInputStream()=default;
#define STREAM_SWAP_READ(type,name) virtual bool Read##name(type &value) \
{\
type swap_value; \
\
if(!Read(swap_value)) \
return(false); \
\
value=EndianSwap(swap_value); \
return(true); \
} \
\
virtual int64 Read##name(type *data,const int64 count) \
{ \
if(count<=0)return(count); \
if(!data)return(-1); \
\
const int64 result=ReadArrays(data,count); \
\
if(result<=0)return(result); \
\
EndianSwap(data,result); \
return(result); \
}
STREAM_SWAP_READ(int16, Int16 );
STREAM_SWAP_READ(int32, Int32 );
STREAM_SWAP_READ(int64, Int64 );
STREAM_SWAP_READ(uint16, Uint16 );
STREAM_SWAP_READ(uint32, Uint32 );
STREAM_SWAP_READ(uint64, Uint64 );
STREAM_SWAP_READ(u16char, UTF16Char);
STREAM_SWAP_READ(float, Float );
STREAM_SWAP_READ(double, Double );
#undef STREAM_SWAP_READ
};//class SwapDataInputStream
#if HGL_ENDIAN == HGL_LITTLE_ENDIAN
typedef DirectDataInputStream LEDataInputStream;
typedef SwapDataInputStream BEDataInputStream;
#else
typedef DirectDataInputStream BEDataInputStream;
typedef SwapDataInputStream LEDataInputStream;
#endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
}//namespace io
}//namespace hgl
#endif//HGL_IO_ENDIAN_DATA_INPUT_STREAM_INCLUDE

View File

@ -0,0 +1,103 @@
#ifndef HGL_IO_ENDIAN_DATA_OUTPUT_STREAM_INCLUDE
#define HGL_IO_ENDIAN_DATA_OUTPUT_STREAM_INCLUDE
#include<hgl/io/DataOutputStream.h>
#include<hgl/endian/Endian.h>
namespace hgl
{
namespace io
{
class DirectDataOutputStream:public DataOutputStream
{
public:
DirectDataOutputStream(OutputStream *os):DataOutputStream(os)
{
}
virtual ~DirectDataOutputStream()
{
}
#define STREAM_DIRECT_WRITE(type,name) virtual bool Write##name(const type &value) \
{ \
return Write(value); \
} \
\
virtual int64 Write##name(const type *data,const int64 count) \
{ \
if(count<=0)return(count); \
if(!data)return(-1); \
\
return WriteArrays(data,count); \
}
STREAM_DIRECT_WRITE(int16, Int16 );
STREAM_DIRECT_WRITE(int32, Int32 );
STREAM_DIRECT_WRITE(int64, Int64 );
STREAM_DIRECT_WRITE(uint16, Uint16 );
STREAM_DIRECT_WRITE(uint32, Uint32 );
STREAM_DIRECT_WRITE(uint64, Uint64 );
STREAM_DIRECT_WRITE(u16char,UTF16Char);
STREAM_DIRECT_WRITE(float, Float );
STREAM_DIRECT_WRITE(double, Double );
#undef STREAM_DIRECT_WRITE
};//class DirectDataOutputStream
class SwapDataOutputStream:public DataOutputStream
{
public:
SwapDataOutputStream(OutputStream *os):DataOutputStream(os)
{
}
virtual ~SwapDataOutputStream()
{
}
#define STREAM_SWAP_WRITE(type,name) virtual bool Write##name(const type &value) \
{\
return Write(EndianSwap(value)); \
} \
\
virtual int64 Write##name(const type *data,const int64 count) \
{ \
if(count<=0)return(count); \
if(!data)return(-1); \
\
SharedArray<type> swap_data=new type[count]; \
\
EndianSwap<type>(swap_data,data,count); \
\
return WriteArrays<type>(swap_data,count); \
}
STREAM_SWAP_WRITE(int16, Int16 );
STREAM_SWAP_WRITE(int32, Int32 );
STREAM_SWAP_WRITE(int64, Int64 );
STREAM_SWAP_WRITE(uint16, Uint16 );
STREAM_SWAP_WRITE(uint32, Uint32 );
STREAM_SWAP_WRITE(uint64, Uint64 );
STREAM_SWAP_WRITE(u16char, UTF16Char);
STREAM_SWAP_WRITE(float, Float );
STREAM_SWAP_WRITE(double, Double );
#undef STREAM_SWAP_WRITE
};//class SwapDataOutputStream
#if HGL_ENDIAN == HGL_LITTLE_ENDIAN
typedef DirectDataOutputStream LEDataOutputStream;
typedef SwapDataOutputStream BEDataOutputStream;
#else
typedef DirectDataOutputStream BEDataOutputStream;
typedef SwapDataOutputStream LEDataOutputStream;
#endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
}//namespace io
}//namespace hgl
#endif//HGL_IO_ENDIAN_DATA_OUTPUT_STREAM_INCLUDE

83
inc/hgl/io/FileAccess.h Normal file
View File

@ -0,0 +1,83 @@
#ifndef HGL_IO_FILE_ACCESS_INCLUDE
#define HGL_IO_FILE_ACCESS_INCLUDE
#include<hgl/type/BaseString.h>
#include<hgl/io/SeekAccess.h>
#include<sys/stat.h>
namespace hgl
{
namespace io
{
enum FileOpenMode ///文件访问模式枚举
{
fomNone=0,
fomCreate, ///<创建文件,如存在则失败
fomCreateTrunc, ///<强制创建,如存在则抹掉
fomCreateTemp,
fomOnlyRead, ///<只读方式
fomOnlyWrite, ///<只写方式
fomReadWrite, ///<可读可写
fomAppend, ///<追加模式
fomEnd
};//enum FileOpenMode
/**
* 访
*/
class FileAccess ///文件访问实例管理类
{
protected:
OSString filename;
int fp;
struct_stat64 file_state;
FileOpenMode mode;
public:
FileAccess();
virtual ~FileAccess();
virtual bool Open(const OSString &,FileOpenMode fom); ///<以指定模式打开一个文件
virtual bool Create(const OSString &fn){return Open(fn,fomCreate);} ///<创建一个新文件,如文件已存在则创建失败
virtual bool CreateTrunc(const OSString &fn){return Open(fn,fomCreateTrunc);} ///<创建一个新文件,如文件已存在则抹消它
virtual bool OpenRead(const OSString &fn){return Open(fn,fomOnlyRead);} ///<以只读模式打开一个文件
virtual bool OpenWrite(const OSString &fn){return Open(fn,fomOnlyWrite);} ///<以只写模式打开一个文件
virtual bool OpenReadWrite(const OSString &fn){return Open(fn,fomReadWrite);} ///<以读写模式打开一个文件
virtual bool CreateTemp();
virtual void Close(); ///<关闭文件
virtual void CloseRead(); ///<仅关闭读取
virtual void CloseWrite(); ///<仅关闭写入
virtual int GetFileHandle()const{return fp;}
virtual bool CanRead()const; ///<文件是否可读
virtual bool CanPeek()const{return(CanRead()&&CanSeek());} ///<文件是否可预读
virtual bool CanWrite()const; ///<文件是否可写
virtual bool CanSeek()const; ///<文件是否可定位访问指针
virtual bool CanRestart()const{return CanSeek();} ///<文件是否可复位访问
virtual bool CanSize()const{return(true);} ///<文件是否可取得长度
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<定位访问指针
virtual int64 Tell()const; ///<取得访问指针位置
virtual int64 GetSize(); ///<取得文件长度
virtual bool Restart(); ///<复位访问指针
virtual int64 Read(void *,int64); ///<读取指定长度数据
virtual int64 Peek(void *,int64); ///<预读指定长度数据
virtual int64 Write(const void *,int64); ///<写入指定长度数据
virtual int64 AvailableRead(); ///<剩下的可读数据
virtual int64 Read(int64,void *,int64); ///<在指定位置读取指定长度的数据
virtual int64 Write(int64,const void *,int64); ///<在指定位置写入指定长度的数据
};//class FileAccess
}//namespace io
}//namespace hgl
#endif//HGL_IO_FILE_ACCESS_INCLUDE

View File

@ -0,0 +1,78 @@
#ifndef HGL_IO_FILE_INPUT_STREAM_INCLUDE
#define HGL_IO_FILE_INPUT_STREAM_INCLUDE
#include<hgl/io/InputStream.h>
#include<hgl/io/FileAccess.h>
namespace hgl
{
namespace io
{
/**
*
*/
class FileInputStream:public InputStream ///文件输入流类
{
protected:
SharedPtr<FileAccess> file; ///<文件访问指针
public:
FileInputStream();
FileInputStream(SharedPtr<FileAccess> &);
virtual ~FileInputStream();
virtual bool Open(const OSString &); ///<打开文件
virtual void Close(); ///<关闭文件输入流
virtual int GetFileHandle()const{return file->GetFileHandle();}
virtual int64 Read(void *,int64); ///<读取数据
virtual int64 Peek(void *,int64); ///<预读数据
virtual bool CanSeek()const; ///<是否可移动访问指针
virtual bool CanRestart()const; ///<是否可复位访问
virtual bool CanSize()const; ///<是否可访问文件长度
virtual bool CanPeek()const; ///<是否可预读数据
virtual int64 Skip(int64); ///<跳过指定字节
virtual int64 Tell()const; ///<取当前位置
virtual int64 GetSize()const; ///<取得文件长度
virtual bool Restart(); ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<移动访问指针
virtual int64 Available()const; ///<剩下的可以不受阻塞访问的字节数
virtual int64 Read(int64,void *,int64); ///<在指定位置读取指定长度的数据
};//class FileInputStream
class OpenFileInputStream
{
FileInputStream *fis;
public:
OpenFileInputStream(const OSString &filename)
{
fis=new FileInputStream();
if(!fis->Open(filename))
{
delete fis;
fis=nullptr;
}
}
~OpenFileInputStream()
{
SAFE_CLEAR(fis);
}
const bool operator !(){return !fis;}
operator FileInputStream *(){return fis;}
FileInputStream *operator &(){return fis;}
FileInputStream *operator ->(){return fis;}
};//class OpenFileInputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_FILE_INPUT_STREAM_INCLUDE

View File

@ -0,0 +1,93 @@
#ifndef HGL_IO_FILE_OUTPUT_STREAM_INCLUDE
#define HGL_IO_FILE_OUTPUT_STREAM_INCLUDE
#include<hgl/io/OutputStream.h>
#include<hgl/io/FileAccess.h>
namespace hgl
{
namespace io
{
/**
*
*/
class FileOutputStream:public OutputStream ///文件输出流类
{
protected:
SharedPtr<FileAccess> file; ///<文件访问指针
virtual bool OpenFile(const OSString &,FileOpenMode);
public:
FileOutputStream();
FileOutputStream(SharedPtr<FileAccess> &);
virtual ~FileOutputStream();
virtual bool Open(const OSString &fn,FileOpenMode mode){return OpenFile(fn,mode);} ///<打开文件,指定一个模式
virtual bool Open(const OSString &fn){return OpenFile(fn,fomOnlyWrite);} ///<打开文件
virtual bool Create(const OSString &fn){return OpenFile(fn,fomCreate);} ///<创建文件,如存在创建失败
virtual bool CreateTrunc(const OSString &fn){return OpenFile(fn,fomCreateTrunc);} ///<创建文件,如存在则抹去
virtual bool OpenAppend(const OSString &fn){return OpenFile(fn,fomAppend);} ///<打开文件,追加模式
virtual void Close(); ///<关闭文件
virtual int64 Write(const void *,int64); ///<写入数据
virtual bool CanSeek()const; ///<是否可移动访问指针
virtual bool CanRestart()const; ///<是否可复位访问
virtual bool CanSize()const; ///<是否可访问文件长度
virtual int64 Tell()const; ///<取当前位置
virtual int64 GetSize()const; ///<取得文件长度
virtual bool Restart(); ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<移动访问指针
virtual int64 Available()const{return -1;} ///<可不受影响写入的字节数
virtual int64 Write(int64,const void *,int64); ///<在指定位置写入指定长度的数据
};//class FileOutputStream
/**
*
*/
class OpenFileOutputStream
{
FileOutputStream *fos;
public:
OpenFileOutputStream()
{
fos=nullptr;
}
/**
*
* @param filename
* @param mode ()
* @see FileOpenMode
*/
OpenFileOutputStream(const OSString &filename,FileOpenMode mode=fomOnlyWrite)
{
fos=new FileOutputStream();
if(!fos->Open(filename))
{
delete fos;
fos=nullptr;
}
}
~OpenFileOutputStream()
{
SAFE_CLEAR(fos);
}
const bool operator !(){return !fos;}
operator FileOutputStream *(){return fos;}
FileOutputStream *operator &(){return fos;}
FileOutputStream *operator ->(){return fos;}
};//class OpenFileInputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_FILE_OUTPUT_STREAM_INCLUDE

34
inc/hgl/io/IOType.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef HGL_IO_TYPE_INCLUDE
#define HGL_IO_TYPE_INCLUDE
#include<hgl/platform/Platform.h>
namespace hgl
{
namespace io
{
class DataInputStream;
class DataOutputStream;
template<typename T> struct io_type
{
T value;
public:
io_type()=default;
io_type(const T &v){value=v;}
bool Read(DataInputStream *);
bool Write(DataOutputStream *)const;
void operator = (const T &v)
{
value=v;
}
operator T (){return value;}
operator const T ()const{return value;}
};//template<typename T> struct io_type
}//namespace io
}//namespace hgl
#endif//HGL_IO_TYPE_INCLUDE

39
inc/hgl/io/InputStream.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef HGL_IO_INPUT_STREAM_INCLUDE
#define HGL_IO_INPUT_STREAM_INCLUDE
#include<hgl/type/DataType.h>
#include<hgl/io/SeekAccess.h>
namespace hgl
{
namespace io
{
/**
*
*/
class InputStream:public SeekAccess ///数据输入流基类
{
public:
virtual ~InputStream()=default;
virtual void Close()=0; ///<关闭输入流
virtual int64 Read(void *,int64)=0; ///<读取数据
virtual int64 Peek(void *,int64)=0; ///<预览数据
virtual int64 ReadFully(void *buf,int64 buf_size){return Read(buf,buf_size);} ///<充分读取,保证读取到指定长度的数据(不计算超时)
virtual bool CanRestart()const=0; ///<是否可以复位
virtual bool CanSeek()const=0; ///<是否可以定位
virtual bool CanSize()const=0; ///<是否可以取得尺寸
virtual bool CanPeek()const=0; ///<是否可以预览数据
virtual bool Restart()=0; ///<复位访问指针
virtual int64 Skip(int64)=0; ///<跳过指定字节不访问
virtual int64 Seek(int64,SeekOrigin=soBegin)=0; ///<移动访问指针
virtual int64 Tell()const=0; ///<返回当前访问位置
virtual int64 GetSize()const=0; ///<取得流长度
virtual int64 Available()const=0; ///<剩下的可以不受阻塞访问的字节数
};//class InputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_INPUT_STREAM_INCLUDE

View File

@ -0,0 +1,71 @@
#ifndef HGL_IO_JAVA_INPUT_STREAM_INCLUDE
#define HGL_IO_JAVA_INPUT_STREAM_INCLUDE
#include<hgl/io/DataInputStream.h>
namespace hgl
{
namespace io
{
/**
* Java数据输入流<br>
* java.io.DataInputStreamJava程序进行交互
*/
class JavaInputStream
{
protected:
BEDataInputStream *in;
public:
JavaInputStream(InputStream *is)
{
in=new BEDataInputStream(is);
}
virtual ~JavaInputStream()
{
delete in;
}
int64 read (void *ptr,int size){return in?in->ReadFully(ptr,size):-1;}
int skipBytes (int size) {return in?in->Seek(size,soCurrent):-1;}
bool readBoolean (bool &b) {return in?in->ReadBool (b):false;}
bool readByte (int8 &i) {return in?in->ReadInt8 (i):false;}
bool readUnsignedByte (uint8 &i) {return in?in->ReadUint8 (i):false;}
bool readShort (int16 &i) {return in?in->ReadInt16 (i):false;}
bool readUnsignedShort (uint16 &i) {return in?in->ReadUint16 (i):false;}
bool readInt (int32 &i) {return in?in->ReadInt32 (i):false;}
bool readLong (int64 &i) {return in?in->ReadInt64 (i):false;}
bool readFloat (float &f) {return in?in->ReadFloat (f):false;}
bool readDouble (double &d) {return in?in->ReadDouble (d):false;}
bool readChar (u16char &c)
{
if(!in)
return(false);
uint16 c16;
if(!in->Read(c16))
return(false);
c=BigToCurrentEndian(c16);
return(true);
}
bool readChars (u16char *wstr,const int count)
{
return in?in->ReadUTF16BEChars(wstr,count):false;
}
bool readUTF (UTF16String &str)
{
return in?in->ReadUTF8ShortString(str);
}
};//class JavaInputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_JAVA_INPUT_STREAM_INCLUDE

View File

@ -0,0 +1,62 @@
#ifndef HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE
#define HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE
#include<hgl/io/DataOutputStream.h>
namespace hgl
{
namespace io
{
/**
* Java数据输出流<br>
* java.io.DataOutputStreamJava程序进行交互
*/
class JavaOutputStream
{
protected:
BEDataOutputStream *out;
public:
JavaOutputStream(OutputStream *os)
{
out=new BEDataOutputStream(os);
}
virtual ~JavaOutputStream()
{
delete out;
}
int64 write (const void *ptr,int size) {return out?out->WriteFully(ptr,size):-1;}
bool writeBoolean (const bool &b) {return out?out->WriteBool (b):false;}
bool writeByte (const int8 &i) {return out?out->WriteInt8 (i):false;}
bool writeUnsignedByte (const uint8 &i) {return out?out->WriteUint8 (i):false;}
bool writeShort (const int16 &i) {return out?out->WriteInt16 (i):false;}
bool writeUnsignedShort (const uint16 &i) {return out?out->WriteUint16(i):false;}
bool writeInt (const int32 &i) {return out?out->WriteInt32 (i):false;}
bool writeLong (const int64 &i) {return out?out->WriteInt64 (i):false;}
bool writeFloat (const float &f) {return out?out->WriteFloat (f):false;}
bool writeDouble (const double &d) {return out?out->WriteDouble(d):false;}
bool writeChar (const u16char &c)
{
if(!out)
return(false);
return out->Write(ToBigEndian(c));
}
bool writeChars (const u16char *wstr,const int64 count)
{
return out?out->WriteUTF16BEChars(wstr,count):false;
}
bool writeUTF (const UTF8String &str){return out?out->WriteUTF8ShortString(str);}
bool writeUTF (const UTF16String &str){return out?out->WriteUTF8ShortString(str);}
};//class JavaOutputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE

View File

@ -0,0 +1,163 @@
#ifndef HGL_IO_MEMORY_INPUT_STREAM_INCLUDE
#define HGL_IO_MEMORY_INPUT_STREAM_INCLUDE
#include<hgl/type/MemBlock.h>
#include<hgl/io/InputStream.h>
namespace hgl
{
namespace io
{
/**
*
*/
class MemoryInputStream:public InputStream ///内存数据输入流
{
protected:
const uint8 *buf;
size_t buf_size;
size_t cur_pos;
public:
MemoryInputStream()
{
buf=0;
buf_size=0;
cur_pos=0;
}
virtual ~MemoryInputStream()
{
}
/**
*
* @param data
* @param size
* @return
*/
bool Link(const void *data,const size_t size)
{
if(!data)
return(false);
buf=(uint8 *)data;
buf_size=size;
cur_pos=0;
return(true);
}
/**
* cur_pos
* @param data
* @param size
* @return
*/
bool Update(void *data,size_t size)
{
if(!data)
return(false);
buf=(uint8 *)data;
buf_size=size;
return(true);
}
void Unlink()
{
buf=0;
}
void Close()
{
Unlink();
}
int64 Read(void *data,int64 size)
{
const int result=Peek(data,size);
if(result>0)
cur_pos+=result;
return result;
}
int64 Peek(void *data,int64 size)
{
if(!buf||!data||size<0)
return(-1);
if(cur_pos+size>buf_size)
size=buf_size-cur_pos;
if(size<=0)
return(0);
memcpy(data,buf+cur_pos,size);
return size;
}
bool CanRestart()const{return true;}
bool CanSeek()const{return true;}
bool CanSize()const{return true;}
bool CanPeek()const{return true;}
bool Restart()
{
cur_pos=0;
return(true);
}
int64 Skip(int64 bytes)
{
return Seek(bytes,soCurrent);
}
int64 Seek(int64 off,SeekOrigin so)
{
if(!CanSeek())return(-1);
if(so==soCurrent)
{
off+=cur_pos;
}
else
if(so==soEnd)
{
off+=buf_size;
}
if(off<0||off>=buf_size)
return(-1);
cur_pos=off;
return cur_pos;
}
int64 Tell()const
{
if(!buf)return(-1);
return cur_pos;
}
int64 GetSize()const
{
if(!buf)return(-1);
return buf_size;
}
int64 Available()const
{
if(!buf)return(-1);
return buf_size-cur_pos;
}
};//class MemoryInputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_MEMORY_INPUT_STREAM_INCLUDE

View File

@ -0,0 +1,236 @@
#ifndef HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE
#define HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE
#include<hgl/type/MemBlock.h>
#include<hgl/io/OutputStream.h>
namespace hgl
{
namespace io
{
/**
*
*/
class MemoryOutputStream:public OutputStream ///内存数据输出流
{
protected:
uint8 *buf;
size_t max_size;
size_t buf_size;
size_t cur_pos;
bool one;
public:
MemoryOutputStream()
{
buf=0;
max_size=0;
buf_size=0;
cur_pos=0;
one=false;
}
virtual ~MemoryOutputStream()
{
Close();
}
void *GetData()const{return buf;}
/**
* delete[]
* @param len
* @return
*/
void *CreateCopyData(int *len)const
{
if(buf_size<=0)
return(nullptr);
uint8 *data=new uint8[buf_size+1];
memcpy(data,buf,buf_size);
data[buf_size]=0;
if(len)
*len=buf_size;
return data;
}
/**
*
* @param ptr
* @param size
* @param one_instance (MemoryOutputStream类负责释放)
* @return
*/
bool Link(void *ptr,size_t size,bool one_instance=false)
{
if(!ptr||!size)
return(false);
buf=(uint8 *)ptr;
buf_size=size;
max_size=size;
cur_pos=0;
one=one_instance;
return(true);
}
/**
* cur_pos
* @param ptr
* @param size
* @return
*/
bool Update(void *ptr,size_t size)
{
if(!ptr||!size)
return(false);
buf=(uint8 *)ptr;
buf_size=size;
max_size=0;
return(true);
}
void Unlink()
{
buf=0;
buf_size=0;
max_size=0;
}
bool Create(int64 size)
{
Close();
if(size<=0)
return(false);
buf=(uint8 *)hgl_malloc(size);
if(!buf)
return(false);
one=true;
cur_pos=0;
buf_size=size;
max_size=size;
return(true);
}
void Close() override
{
if(buf)
{
if(one)
hgl_free(buf);
buf=0;
}
buf_size=0;
max_size=0;
}
void ClearData()
{
cur_pos=0;
buf_size=0;
}
int64 Write(const void *ptr,int64 size) override
{
if(!ptr||size<0)
return(-1);
if(!buf)
{
if(!Create(size))
return(-1);
}
if(cur_pos+size>buf_size)
{
if(one)
{
buf_size=cur_pos+size;
if(buf_size>max_size)
{
max_size=power_to_2(buf_size);
buf=(uint8 *)hgl_realloc(buf,max_size);
}
}
else
size=buf_size-cur_pos;
}
if(size<=0)
return(0);
memcpy(buf+cur_pos,ptr,size);
cur_pos+=size;
return size;
}
bool CanRestart()const override{return true;}
bool CanSeek()const override{return true;}
bool CanSize()const override{return true;}
bool Restart() override
{
cur_pos=0;
return(true);
}
int64 Seek(int64 off,SeekOrigin so=soBegin) override
{
if(!CanSeek())return(-1);
if(so==soCurrent)
{
off+=cur_pos;
}
else
if(so==soEnd)
{
off+=buf_size;
}
if(off<0||off>=buf_size)
return(-1);
cur_pos=off;
return cur_pos;
}
int64 Tell()const override
{
return cur_pos;
}
int64 GetSize()const override
{
return buf_size;
}
int64 Available()const override
{
return buf_size-cur_pos;
}
};//class MemoryOutputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE

36
inc/hgl/io/OutputStream.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef HGL_IO_OUTPUT_STREAM_INCLUDE
#define HGL_IO_OUTPUT_STREAM_INCLUDE
#include<hgl/type/DataType.h>
#include<hgl/io/SeekAccess.h>
namespace hgl
{
namespace io
{
/**
*
*/
class OutputStream:public SeekAccess ///数据输出流基类
{
public:
virtual ~OutputStream()=default;
virtual void Close()=0; ///<关闭输出流
virtual int64 Write(const void *,int64)=0; ///<写入数据
virtual int64 WriteFully(const void *buf,int64 buf_size){return Write(buf,buf_size);} ///<充分写入,保证完整写入指定长度的数据
virtual bool CanRestart()const=0; ///<是否可以复位
virtual bool CanSeek()const=0; ///<是否可以定位
virtual bool CanSize()const=0; ///<是否可以取得尺寸
virtual bool Restart()=0; ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin)=0; ///<移动访问指针
virtual int64 Tell()const=0; ///<返回当前访问位置
virtual int64 GetSize()const=0; ///<取得流长度
virtual int64 Available()const=0; ///<剩下的可以不受阻塞写入的字节数
};//class OutputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_OUTPUT_STREAM_INCLUDE

View File

@ -0,0 +1,47 @@
#ifndef HGL_IO_RANDOM_ACCESS_FILE_INCLUDE
#define HGL_IO_RANDOM_ACCESS_FILE_INCLUDE
#include<hgl/io/InputStream.h>
#include<hgl/io/OutputStream.h>
#include<hgl/io/FileAccess.h>
namespace hgl
{
namespace io
{
/**
* 访</p>
* DataInputStream/DataOutputStream包含引用访
*/
class RandomAccessFile:public InputStream,public OutputStream
{
protected:
SharedPtr<FileAccess> file; ///<文件访问指针
public:
RandomAccessFile();
RandomAccessFile(SharedPtr<FileAccess> &);
~RandomAccessFile();
virtual bool Open(const OSString &); ///<打开文件
virtual void Close(); ///<关闭文件
virtual int64 Read(void *,int64); ///<读取数据
virtual int64 Write(const void *,int64); ///<写入数据
virtual int64 Read(int64,void *,int64); ///<在指定位置读取指定长度的数据
virtual int64 Write(int64,const void *,int64); ///<在指定位置写入指定长度的数据
virtual bool CanSeek()const; ///<是否可移动访问指针
virtual bool CanRestart()const; ///<是否可复位访问
virtual bool CanSize()const; ///<是否可访问文件长度
virtual int64 Tell()const; ///<取当前位置
virtual int64 GetSize(); ///<取得文件长度
virtual bool Restart(); ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<移动访问指针
};//class RandomAccessFile
}//namespace io
}//namespace hgl
#endif//HGL_IO_RANDOM_ACCESS_FILE_INCLUDE

36
inc/hgl/io/SeekAccess.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef HGL_IO_SEEK_ACCESS_INCLUDE
#define HGL_IO_SEEK_ACCESS_INCLUDE
#include<hgl/type/DataType.h>
namespace hgl
{
namespace io
{
enum_int(SeekOrigin) /// 资源偏移方向枚举
{
soBegin=0, ///<从资源最开始处开始offset必须大于0。移到资源的offset位置
soCurrent, ///<从资源当前位置开始移到资源的Position+offset位置
soEnd ///<从资源的结束位置开始offset必须小于0表示结束前的字符数
};//enum SeekOrigin
/**
* 访
*/
class SeekAccess
{
public:
virtual ~SeekAccess()=default;
virtual bool CanRestart()const=0; ///<是否可以复位
virtual bool CanSeek()const=0; ///<是否可以定位
virtual bool CanSize()const=0; ///<是否可以取得尺寸
virtual bool Restart()=0; ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin)=0; ///<移动访问指针
virtual int64 Tell()const=0; ///<返回当前访问位置
virtual int64 GetSize()const=0; ///<取得文件长度
};//class SeekAccess
}//namespace io
}//namespace hgl
#endif//HGL_IO_SEEK_ACCESS_INCLUDE

View File

@ -0,0 +1,176 @@
#ifndef HGL_IO_TEXT_OUTPUT_STREAM_INCLUDE
#define HGL_IO_TEXT_OUTPUT_STREAM_INCLUDE
#include<hgl/endian/Endian.h>
#include<hgl/type/StringList.h>
namespace hgl
{
namespace io
{
/**
* <br>
*
*/
class TextOutputStream
{
protected:
ByteOrderMask bom; ///<文本编码
DataOutputStream *out; ///<数据输出流
public:
TextOutputStream(ByteOrderMask _bom,DataOutputStream *_out)
{
bom=_bom;
out=_out;
}
virtual ~TextOutputStream()
{
delete out;
}
const ByteOrderMask GetBOM()const
{
return bom;
}
DataOutputStream *GetDataOutputStream()
{
return out;
}
operator DataOutputStream *()
{
return out;
}
bool WriteBOM() ///<写入文本文件bom头
{
if(!out)return(false);
const BOMFileHeader *bom_item=BOMData+bom;
return(out->Write(bom_item->data,bom_item->size)==bom_item->size);
}
virtual bool WriteChars(const char *,int64)=0; ///<写入一个字符串
virtual bool WriteChars(const u16char *,int64)=0; ///<写入一个字符串
template<typename N>
bool WriteString(const BaseString<N> &str) ///<写入一个字符串
{
return WriteChars(str.c_str(),str.Length());
}
bool WriteLineEnd() ///<写入一个换行符
{
return WriteChars(HGL_LINE_END,HGL_LINE_END_SIZE);
}
template<typename N>
bool WriteLine(const N *str,int64 size)
{
if(!WriteChars(str,size))
return(false);
return WriteLineEnd();
}
template<typename N>
bool WriteLine(const BaseString<N> &str)
{
return WriteLine(str.c_str(),str.Length());
}
/**
* ()
*/
template<typename N>
bool WriteText(const StringList<N> &sl)
{
const int count=sl.GetCount();
for(int i=0;i<count;i++)
if(!WriteLine(sl[i]))
return(false);
return(true);
}
/**
* (2)
* @return
*/
template<typename T>
bool Write(const StringList<T> &sl)
{
const int count=sl.GetCount();
if(!out->WriteInt32(count)) //写入行数
return(false);
if(count<=0)
return(true);
SharedArray<int32> line_length=new int32[count];
SharedArray<T *> str_list=new T *[count];
int32 *line_p=line_length;
T **str_p=str_list;
int32 total=0;
for(int i=0;i<count;i++)
{
const BaseString<T> &str=sl[i];
const int len=str.Length();
total+=len;
*line_p++=len;
*str_list++=str.c_str();
}
if(out->WriteInt32(line_length,count)!=count) //写入每行长度
return(false);
line_p=line_length;
str_p=str_list;
SharedArray<T> text=new T[total];
T *text_p=text;
for(int i=0;i<count;i++)
{
const int len=*line_p++;
memcpy(text_p,*str_p++,len*sizeof(T));
text_p+=len;
}
return WriteChars(text,total);
}
};//class TextOutputStream
template<ByteOrderMask BOM> class EndianTextOutputStream:public TextOutputStream ///文本输出流
{
public:
EndianTextOutputStream(OutputStream *);
bool WriteChars(const char *,int64); ///<写入一个字符串
bool WriteChars(const u16char *,int64); ///<写入一个字符串
};//template<ByteOrderMask BOM> class EndianTextOutputStream
typedef EndianTextOutputStream<bomUTF8 > UTF8TextOutputStream;
typedef EndianTextOutputStream<bomUTF16LE> UTF16LETextOutputStream;
typedef EndianTextOutputStream<bomUTF16BE> UTF16BETextOutputStream;
template<typename T> TextOutputStream *CreateTextOutputStream(OutputStream *os);
}//namespace io
}//namespace hgl
#endif//HGL_IO_TEXT_OUTPUT_STREAM_INCLUDE

View File

@ -0,0 +1,36 @@
#ifndef HGL_EXTERNAL_MODULE_INCLUDE
#define HGL_EXTERNAL_MODULE_INCLUDE
#include<hgl/type/DataType.h>
#include<hgl/platform/FuncLoad.h>
#include OS_EXTERNAL_H
namespace hgl
{
/**
* ,Windows/Linux/BSD/MacOSX<br>
* Windows .DLL<br>
* FreeBSD/MacOSX .dylib<br>
* Linux .so
*/
class ExternalModule ///外部模块调用类
{
ExternalModulePointer fp;
public: //方法
ExternalModule(); ///<本类构造函数
ExternalModule(ExternalModulePointer); ///<本类构造函数
virtual ~ExternalModule(); ///<本类析构函数
bool Load(const os_char *); ///<加载一个外部模块
void Clear(); ///<清除当前模块
void *FindFunc(const char *); ///<查找函数
void *GetFunc(const char *); ///<取得函数
int Get(FuncLoad *); ///<加载函数列表
};//class ExternalModule
ExternalModule *LoadExternalModule(const os_char *); ///<加载一个外部模块
}//namespace hgl
#endif//HGL_EXTERNAL_MODULE_INCLUDE

View File

@ -0,0 +1,31 @@
#ifndef HGL_FUNC_LOAD_INCLUDE
#define HGL_FUNC_LOAD_INCLUDE
namespace hgl
{
/**
*
*/
struct FuncLoad
{
char func_name[64]; ///<函数名称
void **func_pointer; ///<函数指针
};//struct FuncLoad
#define HGL_FUNC_LOAD_LIST_BEGIN(name) struct FuncLoad name[]={
#define HGL_FUNC_LOAD(name) {#name,(void **)&name},
#define HGL_FUNC_LOAD_LIST_END {"",(void **)0}};
inline void ClearFuncLoadPointer(struct FuncLoad *flp)
{
if(!flp)return;
while(flp->func_pointer)
{
flp->func_pointer=(void **)0;
++flp;
}
}
}//namespace hgl
#endif//HGL_FUNC_LOAD_INCLUDE

View File

@ -0,0 +1,69 @@
#ifndef HGL_SYSTEMINFO_INCLUDE
#define HGL_SYSTEMINFO_INCLUDE
#include<hgl/type/DataType.h>
#include<hgl/type/BaseString.h>
namespace hgl
{
/**
*
*/
struct MemInfo ///内存信息结构体
{
uint64 AvailPhys; ///<有效物理内存
uint64 TotalPhys; ///<总共物理内存
uint64 AvailPageFile; ///<有效页面文件
uint64 TotalPageFile; ///<总共页面文件
uint64 AvailVirtual; ///<有效虚拟内存
uint64 TotalVirtual; ///<总计虚拟内存
public:
MemInfo();
};//struct MemInfo
/**
*
*/
struct SystemPath ///操作系统及引擎相关路径
{
OSString start; ///<当前应用程序起始路径
OSString os; ///<操作系统路径
OSString osfont; ///<操作系统字库路径
OSString library; ///<操作系统辅助库路径
OSString common_data; ///<所有用户共用应用程序数据路径
OSString local_data; ///<本地应用程序数据路径
OSString temp; ///<临时文件路径
OSString mydata; ///<当前用户应用程序数据保存路径
OSString myprogram; ///<“我的程序”路径(Windows下为开始菜单程序路径,Mac下为应用程序路径)
OSString mydesktop; ///<“桌面”路径
OSString desktop; ///<所有用户桌面路径
OSString engine; ///<引擎所在路径
OSString plug_ins; ///<引擎插件路径
};//struct SystemPath
/**
*
*/
struct SystemInfo ///系统信息结构
{
MemInfo mem; ///<内存信息
u16char os_name[256]; ///<操作系统全名
SystemPath path; ///<系统相关路径
public:
SystemInfo();
};//struct SystemInfo
}//namespace hgl
#endif//HGL_SYSTEMINFO_INCLUDE

View File

@ -1,5 +0,0 @@
[Dolphin]
PreviewsShown=false
Timestamp=2018,11,27,14,37,5
Version=4
ViewMode=1

View File

@ -1,5 +0,0 @@
[Dolphin]
PreviewsShown=false
Timestamp=2018,11,27,14,37,9
Version=4
ViewMode=1

29
inc/hgl/proc/Fifo.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef HGL_MULTI_PROC_FIFO_INCLUDE
#define HGL_MULTI_PROC_FIFO_INCLUDE
#include<hgl/platform/Platform.h>
namespace hgl
{
/**
*
*/
class Fifo ///命名管道通信
{
public:
char filename[HGL_MAX_PATH];
int fd;
public:
Fifo()
{
*filename=0;
fd=-1;
}
bool Create(const char *); ///<创建一个管道通信文件(注:只需要文件名,不需要完整路径)
};//namespace hgl
}//namespace hgl
#endif//HGL_MULTI_PROC_FIFO_INCLUDE

View File

@ -0,0 +1,35 @@
#ifndef HGL_MULTI_PROC_FIFO_INPUT_STREAM_INCLUDE
#define HGL_MULTI_PROC_FIFO_INPUT_STREAM_INCLUDE
#include<hgl/Fifo.h>
#include<hgl/io/InputStream.h>
namespace hgl
{
namespace io
{
/**
*
*/
class FifoInputStream:public InputStream
{
Fifo *f;
public:
FifoInputStream(Fifo *_f)
{
f=_f;
}
virtual ~FifoInputStream()
{
if(f)
delete f;
}
};//class FifoInputStream
}//namespace io
}//namespace hgl
#endif//HGL_MULTI_PROC_FIFO_INPUT_STREAM_INCLUDE

24
inc/hgl/proc/Pipe.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef HGL_MULTI_PROC_PIPE_INCLUDE
#define HGL_MULTI_PROC_PIPE_INCLUDE
#include<hgl/platform/Platform.h>
#if HGL_OS==HGL_OS_Windows
#include<windows.h>
#endif//
namespace hgl
{
#if HGL_OS==HGL_OS_Windows
using pipe_ptr=HANDLE;
constexpr pipe_ptr PIPE_NULL=nullptr;
#else
using pipe_ptr=int;
constexpr pipe_ptr PIPE_NULL=-1;
#endif//
using pipe_pair=pipe_ptr[2];
bool CreatePipe(pipe_pair &); ///<创建一对通信管道
}//namespace hgl
#endif//HGL_MULTI_PROC_PIPE_INCLUDE

41
inc/hgl/proc/Proc.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef HGL_PROCESS_INCLUDE
#define HGL_PROCESS_INCLUDE
#include<hgl/type/StringList.h>
namespace hgl
{
/**
*
*/
class Process ///进程管理类
{
OSString work_path;
OSString filename;
StringList<OSString> args;
int pid;
public:
Process()
{
pid=-1;
}
virtual ~Process()
{
}
bool SetWorkPath(const OSString &wp); ///<设置工作目录
bool SetExecFile(const OSString &ef); ///<设置执行文件
void AddArgv(const OSString &argv){if(!argv.IsEmpty())args.Add(argv);} ///<增加一个参数
void ClearArgs(){args.Clear();} ///<清除所有参数
bool Execute(); ///<执行程序
bool Wait(); ///<等待子进程暂停或是终止
bool Kill(); ///<杀掉子进程
bool RequestTerminate(); ///<请求子进程终止
};//class Process
}//namespace hgl
#endif//HGL_PROCESS_INCLUDE

37
inc/hgl/proc/ProcMutex.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef HGL_PROCESS_MUTEX_INCLUDE
#define HGL_PROCESS_MUTEX_INCLUDE
#include<hgl/type/DataType.h>
#if HGL_OS!=HGL_OS_Windows
#include<semaphore.h>
#endif//HGL_OS!=HGL_OS_Windows
namespace hgl
{
/**
*
*/
class ProcMutex ///进程排斥
{
#if HGL_OS==HGL_OS_Windows
void *lock;
#else
sem_t *lock;
#endif//HGL_OS==HGL_OS_Windows
public:
ProcMutex();
~ProcMutex(){Clear();}
bool Create(const os_char *); ///<创建进程排斥
void Clear(); ///<清除进程排斥
bool Lock(); ///<锁定
bool TryLock(); ///<尝试锁定
bool Unlock(); ///<解锁
};//class ProcMutex
}//namespace hgl
#endif//HGL_PROCESS_MUTEX_INCLUDE

Some files were not shown because too many files have changed in this diff Show More