添加Linux系统下缺少的文件

This commit is contained in:
hyzboy 2019-05-07 03:18:39 +08:00
parent 351f2a3862
commit 40b57bf7a7
10 changed files with 337 additions and 145 deletions

View File

@ -89,7 +89,7 @@ private:
if(!ubo_mvp)
return(false);
return desciptor_sets->UpdateUBO(material->GetUBOBinding("world"),*ubo_mvp);
return desciptor_sets->UpdateUBO(material->GetUBO("world"),*ubo_mvp);
}
void InitVBO()

10
inc/hgl/platform/Exit.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef HGL_EXIT_INCLUDE
#define HGL_EXIT_INCLUDE
namespace hgl
{
typedef int (*SignalAppExitFunc)(); //程序退出处理事件函数
void SetSignalAppExit(SignalAppExitFunc); //设置程序退出处理事件函数
}//namespace hgl
#endif//HGL_EXIT_INCLUDE

View File

@ -40,7 +40,8 @@
SET(PLATFORM_FILE_SOURCE ${PLATFORM_FILE_SOURCE}
UNIX/ProgramPath.cpp)
SET(PLATFORM_WINDOW_SOURCE UNIX/XCBWindow.cpp)
SET(PLATFORM_WINDOW_SOURCE UNIX/XCBWindow.cpp
UNIX/XCBVulkan.cpp)
ENDIF()
ENDIF()

View File

@ -0,0 +1,24 @@
#include<hgl/platform/Exit.h>
#include<signal.h>
namespace hgl
{
static SignalAppExitFunc app_exit_func=nullptr;
void exit_signal_proc(int n,siginfo_t *si,void *)
{
}
void SetSignalAppExit(SignalAppExitFunc func)
{
if(!func)return;
app_exit_func=func;
struct sigaction act;
sigemptyset(&act.sa_mask); /** 清空阻塞信号 **/
act.sa_flags=SA_SIGINFO; /** 设置SA_SIGINFO 表示传递附加信息到触发函数 **/
act.sa_sigaction=exit_signal_proc;
}
}//namespace hgl

View File

@ -1,4 +1,4 @@
#include<hgl/ExternalModule.h>
#include<hgl/platform/ExternalModule.h>
#include<hgl/platform/Platform.h>
#include<hgl/LogInfo.h>

View File

@ -0,0 +1,126 @@
#include<hgl/Logger.h>
#include<hgl/CodePage.h>
#include<hgl/thread/ThreadMutex.h>
#include<unistd.h>
#include<pthread.h>
#ifdef LOG_INFO_TIME
#include<hgl/Time.h>
#endif//LOG_INFO_TIME
namespace hgl
{
namespace logger
{
constexpr uint LOG_BUF_SIZE=4096;
/**
* unix控制台日志插件接口
*/
class LogUnixConsole:public Logger
{
char endline;
char log_buf[LOG_BUF_SIZE];
#ifdef LOGINFO_THREAD_MUTEX
ThreadMutex mutex;
#endif//LOGINFO_THREAD_MUTEX
public:
LogUnixConsole(LogLevel ll):Logger(ll)
{
endline='\n';
}
bool Create(const OSString &)
{
return(true);
}
void Close(){}
#ifdef LOG_INFO_THREAD
void WriteThreadID()
{
memcpy(log_buf,"[Thread:",8);
htos(log_buf+8,128-9,pthread_self());
strcat(log_buf,LOG_BUF_SIZE,']');
write(STDOUT_FILENO,log_buf,strlen(log_buf));
}
#endif//LOG_INFO_THREAD
#ifdef LOG_INFO_TIME
void WriteTime()
{
memcpy(log_buf,"[Time:",6);
ftos(log_buf+6,128-strlen(log_buf),GetDoubleTime());
strcat(log_buf,LOG_BUF_SIZE,']');
write(STDOUT_FILENO,log_buf,strlen(log_buf));
}
#endif//LOG_INFO_TIME
void Write(const u16char *str,int size)
{
#ifdef LOGINFO_THREAD_MUTEX
mutex.Lock();
#endif//LOGINFO_THREAD_MUTEX
#ifdef LOG_INFO_THREAD
WriteThreadID();
#endif//LOG_INFO_THREAD
#ifdef LOG_INFO_TIME
WriteTime();
#endif//LOG_INFO_TIME
int len;
len=u16_to_u8(log_buf,LOG_BUF_SIZE,str,size);
if(len>0)
{
log_buf[len++]='\n';
write(STDOUT_FILENO,log_buf,len);
}
#ifdef LOGINFO_THREAD_MUTEX
mutex.Unlock();
#endif//LOGINFO_THREAD_MUTEX
}
void Write(const char *str,int size)
{
#ifdef LOGINFO_THREAD_MUTEX
mutex.Lock();
#endif//LOGINFO_THREAD_MUTEX
#ifdef LOG_INFO_THREAD
WriteThreadID();
#endif//LOG_INFO_THREAD
#ifdef LOG_INFO_TIME
WriteTime();
#endif//LOG_INFO_TIME
write(STDOUT_FILENO,str,size);
write(STDOUT_FILENO,&endline,1);
#ifdef LOGINFO_THREAD_MUTEX
mutex.Unlock();
#endif//LOGINFO_THREAD_MUTEX
}
};//class LogInterface
Logger *CreateLoggerConsole(const OSString &,LogLevel ll)
{
if(ll<llError)
return(nullptr);
return(new LogUnixConsole(ll));
}
}//logger
}//namespace hgl

View File

@ -0,0 +1,26 @@
#include"XCBWindow.h"
#include<hgl/graph/vulkan/VK.h>
#include<vulkan/vulkan_xcb.h>
VK_NAMESPACE_BEGIN
VkSurfaceKHR CreateRenderDevice(VkInstance vk_inst,Window *win)
{
XCBWindow *xcb_win=(XCBWindow *)win;
VkXcbSurfaceCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = nullptr;
createInfo.connection = xcb_win->GetConnection();
createInfo.window = xcb_win->GetWindow();
VkSurfaceKHR surface;
VkResult res = vkCreateXcbSurfaceKHR(vk_inst, &createInfo, nullptr, &surface);
if (res != VK_SUCCESS)
return(nullptr);
return(surface);
}
VK_NAMESPACE_END

View File

@ -1,24 +1,7 @@
#include"Window.h"
#include<xcb/xcb.h>
#include<xcb/xcb_atom.h>
#include"VK.h"
#include<vulkan/vk_sdk_platform.h>
#include<vulkan/vulkan.h>
#include<vulkan/vulkan_xcb.h>
#include"XCBWindow.h"
namespace hgl
{
namespace graph
{
class XCBWindow:public Window
{
xcb_connection_t *connection;
xcb_screen_t *screen;
xcb_window_t window;
xcb_intern_atom_reply_t *atom_wm_delete_window;
private:
bool InitConnection()
bool XCBWindow::InitConnection()
{
int scr;
@ -36,20 +19,18 @@ namespace hgl
return(true);
}
public:
XCBWindow(const UTF8String &wn):Window(wn)
XCBWindow::XCBWindow(const UTF8String &wn):Window(wn)
{
connection=nullptr;
screen=nullptr;
atom_wm_delete_window=nullptr;
}
~XCBWindow()
XCBWindow::~XCBWindow()
{
}
bool Create(uint w,uint h) override
bool XCBWindow::Create(uint w,uint h)
{
if(w<=0||h<=0)return(false);
if(!InitConnection())return(false);
@ -97,48 +78,33 @@ namespace hgl
}
}
bool Create(uint,uint,uint)override{}
void Close()override
void XCBWindow::Close()
{
xcb_destroy_window(connection, window);
xcb_destroy_window(connection,window);
xcb_disconnect(connection);
}
void Show()override{}
void Hide()override{}
void XCBWindow::SetCaption(const OSString &caption)
{
win_name=caption;
xcb_change_property (connection, XCB_PROP_MODE_REPLACE, window,XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
win_name.Length(), win_name.c_str());
}
public:
bool XCBWindow::MessageProc()
{
return(true);
}
xcb_connection_t *GetConnection(){return connection;}
xcb_window_t GetWindow(){return window;}
};//class XCBWindow:public Window
bool XCBWindow::WaitMessage()
{
return(true);
}
Window *CreateRenderWindow(const UTF8String &win_name)
{
return(new XCBWindow(win_name));
}
}//namespace graph
void InitNativeWindowSystem(){}
}//namespace hgl
VK_NAMESPACE_BEGIN
VkSurfaceKHR CreateRenderDevice(VkInstance vk_inst,Window *win)
{
XCBWindow *xcb_win=(XCBWindow *)win;
VkXcbSurfaceCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = nullptr;
createInfo.connection = xcb_win->GetConnection();
createInfo.window = xcb_win->GetWindow();
VkSurfaceKHR surface;
VkResult res = vkCreateXcbSurfaceKHR(vk_inst, &createInfo, nullptr, &surface);
if (res != VK_SUCCESS)
return(nullptr);
return(surface);
}
VK_NAMESPACE_END

View File

@ -0,0 +1,39 @@
#include<hgl/platform/Window.h>
#include<xcb/xcb.h>
#include<xcb/xcb_atom.h>
namespace hgl
{
class XCBWindow:public Window
{
xcb_connection_t *connection;
xcb_screen_t *screen;
xcb_window_t window;
xcb_intern_atom_reply_t *atom_wm_delete_window;
private:
bool InitConnection();
public:
XCBWindow(const UTF8String &wn);
~XCBWindow();
bool Create(uint w,uint h)override;
bool Create(uint,uint,uint)override{}
void Close()override;
void SetCaption(const OSString &caption) override;
void Show()override{}
void Hide()override{}
bool MessageProc() override;
bool WaitMessage() override;
public:
xcb_connection_t *GetConnection(){return connection;}
xcb_window_t GetWindow(){return window;}
};//class XCBWindow:public Window
}//namespace hgl