添加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

@ -35,13 +35,13 @@ constexpr uint16 index_data[INDEX_COUNT]=
class TestApp:public VulkanApplicationFramework class TestApp:public VulkanApplicationFramework
{ {
private: private:
uint swap_chain_count=0; uint swap_chain_count=0;
vulkan::Material * material =nullptr; vulkan::Material * material =nullptr;
vulkan::DescriptorSets * desciptor_sets =nullptr; vulkan::DescriptorSets * desciptor_sets =nullptr;
vulkan::Renderable * render_obj =nullptr; vulkan::Renderable * render_obj =nullptr;
vulkan::Buffer * ubo_mvp =nullptr; vulkan::Buffer * ubo_mvp =nullptr;
vulkan::Pipeline * pipeline =nullptr; vulkan::Pipeline * pipeline =nullptr;
@ -89,11 +89,11 @@ private:
if(!ubo_mvp) if(!ubo_mvp)
return(false); return(false);
return desciptor_sets->UpdateUBO(material->GetUBOBinding("world"),*ubo_mvp); return desciptor_sets->UpdateUBO(material->GetUBO("world"),*ubo_mvp);
} }
void InitVBO() void InitVBO()
{ {
vertex_buffer =device->CreateVBO(FMT_RG32F,VERTEX_COUNT,vertex_data); vertex_buffer =device->CreateVBO(FMT_RG32F,VERTEX_COUNT,vertex_data);
index_buffer =device->CreateIBO16(INDEX_COUNT,index_data); index_buffer =device->CreateIBO16(INDEX_COUNT,index_data);
@ -144,7 +144,7 @@ private:
public: public:
bool Init() bool Init()
{ {
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT)) if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false); return(false);
@ -191,6 +191,6 @@ int main(int,char **)
return(-1); return(-1);
while(app.Run()); while(app.Run());
return 0; return 0;
} }

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} SET(PLATFORM_FILE_SOURCE ${PLATFORM_FILE_SOURCE}
UNIX/ProgramPath.cpp) UNIX/ProgramPath.cpp)
SET(PLATFORM_WINDOW_SOURCE UNIX/XCBWindow.cpp) SET(PLATFORM_WINDOW_SOURCE UNIX/XCBWindow.cpp
UNIX/XCBVulkan.cpp)
ENDIF() ENDIF()
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/platform/Platform.h>
#include<hgl/LogInfo.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,144 +1,110 @@
#include"Window.h" #include"XCBWindow.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>
namespace hgl namespace hgl
{ {
namespace graph bool XCBWindow::InitConnection()
{ {
class XCBWindow:public Window int scr;
connection=xcb_connect(nullptr,&scr);
if(!connection||xcb_connection_has_error(connection))
return(false);
const xcb_setup_t *setup=xcb_get_setup(connection);
xcb_screen_iterator_t iter=xcb_setup_roots_iterator(setup);
while(scr-->0)xcb_screen_next(&iter);
screen=iter.data;
return(true);
}
XCBWindow::XCBWindow(const UTF8String &wn):Window(wn)
{
connection=nullptr;
screen=nullptr;
atom_wm_delete_window=nullptr;
}
XCBWindow::~XCBWindow()
{
}
bool XCBWindow::Create(uint w,uint h)
{
if(w<=0||h<=0)return(false);
if(!InitConnection())return(false);
window=xcb_generate_id(connection);
uint32_t value_mask,value_list[32];
value_mask=XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
value_list[0] = screen->black_pixel;
value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE;
width=w;
height=h;
xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0,0, width, height, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, (*reply).atom, 4, 32, 1,
&(*atom_wm_delete_window).atom);
free(reply);
xcb_change_property (connection, XCB_PROP_MODE_REPLACE, window,XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
win_name.Length(), win_name.c_str());
xcb_map_window(connection, window);
const uint32_t coords[] =
{ {
xcb_connection_t *connection; (screen->width_in_pixels-width)/2,
xcb_screen_t *screen; (screen->height_in_pixels-height)/2
xcb_window_t window; };
xcb_intern_atom_reply_t *atom_wm_delete_window; xcb_configure_window(connection, window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
xcb_flush(connection);
private: xcb_generic_event_t *e;
while ((e = xcb_wait_for_event(connection))) {
bool InitConnection() if ((e->response_type & ~0x80) == XCB_EXPOSE) break;
{
int scr;
connection=xcb_connect(nullptr,&scr);
if(!connection||xcb_connection_has_error(connection))
return(false);
const xcb_setup_t *setup=xcb_get_setup(connection);
xcb_screen_iterator_t iter=xcb_setup_roots_iterator(setup);
while(scr-->0)xcb_screen_next(&iter);
screen=iter.data;
return(true);
}
public:
XCBWindow(const UTF8String &wn):Window(wn)
{
connection=nullptr;
screen=nullptr;
atom_wm_delete_window=nullptr;
}
~XCBWindow()
{
}
bool Create(uint w,uint h) override
{
if(w<=0||h<=0)return(false);
if(!InitConnection())return(false);
window=xcb_generate_id(connection);
uint32_t value_mask,value_list[32];
value_mask=XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
value_list[0] = screen->black_pixel;
value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE;
width=w;
height=h;
xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0,0, width, height, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, (*reply).atom, 4, 32, 1,
&(*atom_wm_delete_window).atom);
free(reply);
xcb_change_property (connection, XCB_PROP_MODE_REPLACE, window,XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
win_name.Length(), win_name.c_str());
xcb_map_window(connection, window);
const uint32_t coords[] =
{
(screen->width_in_pixels-width)/2,
(screen->height_in_pixels-height)/2
};
xcb_configure_window(connection, window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
xcb_flush(connection);
xcb_generic_event_t *e;
while ((e = xcb_wait_for_event(connection))) {
if ((e->response_type & ~0x80) == XCB_EXPOSE) break;
}
}
bool Create(uint,uint,uint)override{}
void Close()override
{
xcb_destroy_window(connection, window);
xcb_disconnect(connection);
}
void Show()override{}
void Hide()override{}
public:
xcb_connection_t *GetConnection(){return connection;}
xcb_window_t GetWindow(){return window;}
};//class XCBWindow:public Window
Window *CreateRenderWindow(const UTF8String &win_name)
{
return(new XCBWindow(win_name));
} }
}//namespace graph }
void XCBWindow::Close()
{
xcb_destroy_window(connection,window);
xcb_disconnect(connection);
}
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());
}
bool XCBWindow::MessageProc()
{
return(true);
}
bool XCBWindow::WaitMessage()
{
return(true);
}
Window *CreateRenderWindow(const UTF8String &win_name)
{
return(new XCBWindow(win_name));
}
void InitNativeWindowSystem(){}
}//namespace hgl }//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