From 19be1c4d9fb39ab1ceab66b36f2b80cd25da1987 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 6 Nov 2019 20:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BBVKDebugOut=E4=BB=A5=E5=8F=8AV?= =?UTF-8?q?KProperties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/TextureFormat.cpp | 2 + inc/hgl/graph/Spline.cpp | 196 +++++++ inc/hgl/graph/Spline.h | 100 ++++ inc/hgl/graph/TileData.h | 103 ++++ inc/hgl/graph/text/FontInfo.Attrib.h | 25 + inc/hgl/graph/text/FontInfo.h | 51 ++ inc/hgl/graph/text/FontSource.h | 50 ++ inc/hgl/graph/text/TileFont.h | 175 ++++++ inc/hgl/graph/vulkan/VK.h | 6 + inc/hgl/graph/vulkan/VKDebugOut.h | 23 + inc/hgl/graph/vulkan/VKInstance.h | 15 +- inc/hgl/input/Event.h | 68 +++ res/shader/test.geom | 15 + src/RenderDevice/Vulkan/CMakeLists.txt | 1 + src/RenderDevice/Vulkan/VKDebugOut.cpp | 171 ++++++ src/RenderDevice/Vulkan/VKInstance.cpp | 253 +------- src/RenderDevice/Vulkan/VKProperties.cpp | 58 ++ src/Tools/ShaderCompiler/CMakeLists.txt | 2 + src/Tools/ShaderCompiler/main.cpp | 0 src/Tools/TexConv/CMakeLists.txt | 7 + src/Tools/TexConv/MainUnit.cpp | 708 +++++++++++++++++++++++ 21 files changed, 1788 insertions(+), 241 deletions(-) create mode 100644 inc/hgl/graph/Spline.cpp create mode 100644 inc/hgl/graph/Spline.h create mode 100644 inc/hgl/graph/TileData.h create mode 100644 inc/hgl/graph/text/FontInfo.Attrib.h create mode 100644 inc/hgl/graph/text/FontInfo.h create mode 100644 inc/hgl/graph/text/FontSource.h create mode 100644 inc/hgl/graph/text/TileFont.h create mode 100644 inc/hgl/graph/vulkan/VKDebugOut.h create mode 100644 inc/hgl/input/Event.h create mode 100644 res/shader/test.geom create mode 100644 src/RenderDevice/Vulkan/VKDebugOut.cpp create mode 100644 src/RenderDevice/Vulkan/VKProperties.cpp create mode 100644 src/Tools/ShaderCompiler/CMakeLists.txt create mode 100644 src/Tools/ShaderCompiler/main.cpp create mode 100644 src/Tools/TexConv/CMakeLists.txt create mode 100644 src/Tools/TexConv/MainUnit.cpp diff --git a/example/Vulkan/TextureFormat.cpp b/example/Vulkan/TextureFormat.cpp index 240b98a8..85b70230 100644 --- a/example/Vulkan/TextureFormat.cpp +++ b/example/Vulkan/TextureFormat.cpp @@ -52,6 +52,8 @@ int main(int,char **) InitNativeWindowSystem(); + InitVulkanProperties(); + win=CreateRenderWindow(OS_TEXT("VulkanTest")); if(!win) return(false); diff --git a/inc/hgl/graph/Spline.cpp b/inc/hgl/graph/Spline.cpp new file mode 100644 index 00000000..6b5fc542 --- /dev/null +++ b/inc/hgl/graph/Spline.cpp @@ -0,0 +1,196 @@ +#include +#include + +namespace hgl +{ + namespace graph + { + template + Spline::Spline( + int k, + SplineNode node_type) + : + _node_type(node_type), + _k(k), + _point( _k ), + _vec( _k-1 ), + _node( _k + _point.size() ) + { + assert_splines(); + } + + // ----------------------------------------------------------------------------- + + template + void Spline::set_ctrl_points(const std::vector& point) + { + _point = point; + _vec.resize(_point.size() - 1); + for(int i = 0; i < (int)_vec.size(); ++i) + _vec[i] = _point[i + 1] - _point[i]; + set_nodal_vector(); + assert_splines(); + + for(int i = 0; i < (int)_vec.size(); ++i) + _vec[i] /= _node[_k+i] - _node[i+1]; + } + + // ----------------------------------------------------------------------------- + + template + void Spline::get_ctrl_points(std::vector& points) const + { + points = _point; + } + + // ----------------------------------------------------------------------------- + + /// The the nodal vector type + template + void Spline::set_node_type( SplineNode type) + { + _node_type = type; + set_nodal_vector(); + assert_splines(); + } + + // ----------------------------------------------------------------------------- + + template + Point_t Spline::eval_f(Real_t u) const + { + u = std::max(std::min(u, (Real_t)1), (Real_t)0); // clamp between [0 1] + return eval(u, _point, _k, _node); + } + + // ----------------------------------------------------------------------------- + + template + Point_t Spline::eval_df(Real_t u) const + { + u = std::max(std::min(u, (Real_t)1), (Real_t)0); // clamp between [0 1] + return eval(u, _vec, (_k-1), _node, 1) * (Real_t)(_k-1); + } + + // ----------------------------------------------------------------------------- + + template + void Spline::assert_splines() const + { + assert( _k > 1); + assert((int)_point.size() >= _k ); + assert(_node. size() == (_k + _point.size()) ); + assert(_point.size() == (_vec.size() + 1) ); + } + + // ----------------------------------------------------------------------------- + + template + void Spline::set_nodal_vector() + { + if( _node_type == SplineNode::OPEN_UNIFORM) + set_node_to_open_uniform(); + else if( _node_type == spline::eUNIFORM ) + set_node_to_uniform(); + } + + // ----------------------------------------------------------------------------- + + template + void Spline::set_node_to_uniform() + { + const int n = _point.size() - 1; + _node.resize( _k + n + 1 ); + + Real_t step = (Real_t)1 / (Real_t)(n-_k+2); + for (int i = 0; i < (int)_node.size(); ++i){ + _node[i] = ((Real_t)i) * step - step * (Real_t)(_k-1); + } + } + + // ----------------------------------------------------------------------------- + + template + void Spline::set_node_to_open_uniform() + { + _node.resize( _k + _point.size() ); + + int acc = 1; + for (int i = 0; i < (int)_node.size(); ++i) + { + if(i < _k) + _node[i] = 0.; + else if( i >= ((int)_point.size() + 1) ) + _node[i] = 1.; + else{ + _node[i] = (Real_t)acc / (Real_t)(_point.size() + 1 - _k); + acc++; + } + } + } + + // ----------------------------------------------------------------------------- + + template + Point_t Spline:: + + eval(Real_t u, + const std::vector& point, + int k, + const std::vector& node, + int off) const + { + assert( k > 1); + assert((int)point.size() >= k ); + assert_splines(); + int dec = 0; + // TODO: better search with dychotomi ? + // TODO: check for overflow + while( u > node[dec + k + off] ) + dec++; + + // TODO: use buffers in attributes for better performances ? + std::vector p_rec(k, Point_t()); + for(int i = dec, j = 0; i < (dec + k); ++i, ++j) + p_rec[j] = point[i]; + + std::vector node_rec(k + k - 2, (Real_t)0); + for(int i = (dec + 1), j = 0; i < (dec + k + k - 1); ++i, ++j) + node_rec[j] = node[i + off]; + + return eval_rec(u, p_rec, k, node_rec); + } + + // ----------------------------------------------------------------------------- + + template + Point_t Spline:: + + eval_rec(Real_t u, + std::vector p_in, + int k, + std::vector node_in) const + { + if(p_in.size() == 1) + return p_in[0]; + + // TODO: use buffers in attributes for better performances ? + std::vector p_out(k - 1, Point_t()); + for(int i = 0; i < (k - 1); ++i) + { + const Real_t n0 = node_in[i + k - 1]; + const Real_t n1 = node_in[i]; + const Real_t f0 = (n0 - u) / (n0 - n1); + const Real_t f1 = (u - n1) / (n0 - n1); + + p_out[i] = p_in[i] * f0 + p_in[i + 1] * f1; + } + + std::vector node_out(node_in.size() - 2); + for(int i = 1, j = 0; i < ((int)node_in.size()-1); ++i, ++j) + node_out[j] = node_in[i]; + + return eval_rec(u, p_out, (k - 1), node_out); + } + }//namespace graph +}//namespace hgl diff --git a/inc/hgl/graph/Spline.h b/inc/hgl/graph/Spline.h new file mode 100644 index 00000000..84a2cbe1 --- /dev/null +++ b/inc/hgl/graph/Spline.h @@ -0,0 +1,100 @@ +#ifndef HGL_GRAPH_SPLINE_INCLUDE +#define HGL_GRAPH_SPLINE_INCLUDE + +#include +#include + +namespace hgl +{ + namespace graph + { + enum class SplineNode + { + UNIFORM, + OPEN_UNIFORM ///< Connected to the first and last control points + }; + + template class Spline + { + public: + + /// Type of the nodal vector + /// @param k : order of the spline (minimum is two) + /// @param node_type : nodal vector type (uniform, open_uniform) + /// This will define the behavior of the spline with its control points + /// as well as its speed according to its parameter. + Spline(int k = 2, SplineNode node_type = SplineNode::OPEN_UNIFORM); + + /// Set the position of the spline control points. + void set_ctrl_points(const std::vector& point); + + /// Get the control points of the spline + void get_ctrl_points(std::vector& points) const; + + /// The the nodal vector type + void set_node_type( SplineNode type); + + /// Evaluate position of the spline + /// @param u : curve parameter ranging from [0; 1] + Point_t eval_f(Real_t u) const; + + /// Evaluate speed of the spline + Point_t eval_df(Real_t u) const; + + int get_order() const { return _k; } + + private: + // ------------------------------------------------------------------------- + /// @name Class tools + // ------------------------------------------------------------------------- + + void assert_splines() const; + + /// set value and size of the nodal vector depending on the current number + /// of control points + void set_nodal_vector(); + + /// Set values of the nodal vector to be uniform + void set_node_to_uniform(); + + /// Set values of the nodal vector to be open uniform + void set_node_to_open_uniform(); + + /// Evaluate the equation of a splines using the blossom algorithm + /// @param u : the curve parameter which range from the values + /// [node[k-1]; node[point.size()]] + /// @param point : the control points which size must be at least equal to + /// the order of the spline (point.size() >= k) + /// @param k : the spline order (degree == k-1) + /// @param node : the nodal vector which defines the speed of the spline + /// parameter u. The nodal vector size must be equal to (k + point.size()) + /// @param off : offset to apply to the nodal vector 'node' before reading + /// from it. this is useful to compute derivatives. + Point_t eval(Real_t u, + const std::vector& point, + int k, + const std::vector& node, + int off = 0) const; + + Point_t eval_rec(Real_t u, + std::vector p_in, + int k, + std::vector node_in) const; + + // ------------------------------------------------------------------------- + /// @name attributes + // ------------------------------------------------------------------------- + + SplineNode _node_type; ///< Nodal vector type + int _k; ///< spline order + std::vector _point; ///< Control points + std::vector _vec; ///< Control points differences + std::vector _node; ///< Nodal vector + };//class Spline + + using Spline2f=Spline; + using Spline3f=Spline; + }//namespace graph +}//namespace hgl +#include +#endif//HGL_GRAPH_SPLINE_INCLUDE diff --git a/inc/hgl/graph/TileData.h b/inc/hgl/graph/TileData.h new file mode 100644 index 00000000..dd81b042 --- /dev/null +++ b/inc/hgl/graph/TileData.h @@ -0,0 +1,103 @@ +#ifndef HGL_GRAPH_TILE_DATA_INCLUDE +#define HGL_GRAPH_TILE_DATA_INCLUDE + +#include +namespace hgl +{ + namespace graph + { + class Texture2D; + class Renderable; + class Bitmap2D; + + /** + * TileData是一种处理将大量等同贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合的贴图。(注意:Tile的宽高不必是2的幂)。
+ * Tile的增加删除,程序会做自动排序,尽可能小的影响效能。 + */ + class TileData ///Tile数据管理 + { + public: + + struct Object ///Tile对象 + { + int index; + + double fl,ft; + double fw,fh; + + int width,height; + }; + + protected: + + Texture2D *tile_texture; /// class VertexBuffer2; + + /** + * 渲染Tile为一个2D矩形数据到顶点缓冲区上 + * @param obj 要渲制的Tile对象 + * @param vertex 渲染到的2d顶点坐标缓冲区 + * @param tex_coord 渲染到的贴图坐标缓冲区 + * @param left 显示的左边界 + * @param top 显示的上边界 + * @param scale_width 宽度缩放比 + * @param scale_height 高度缩放比 + */ + template + __inline void RenderToVB2DRect( VertexBuffer2 *vertex, + VertexBuffer2 *tex_coord, + const TileData::Object *obj, + const float left, + const float top, + const float scale_width=1.0f, + const float scale_height=1.0f) + { + if(!obj||!vertex||!tex_coord)return; + + tex_coord->WriteRect( obj->fl, + obj->ft, + obj->fw, + obj->fh); + + vertex->WriteRect( left, + top, + scale_width*float(obj->width), + scale_height*float(obj->height)); + } + }//namespace graph +}//namespace hgl +#endif//HGL_GRAPH_TILE_DATA_INCLUDE diff --git a/inc/hgl/graph/text/FontInfo.Attrib.h b/inc/hgl/graph/text/FontInfo.Attrib.h new file mode 100644 index 00000000..cb0c7e4b --- /dev/null +++ b/inc/hgl/graph/text/FontInfo.Attrib.h @@ -0,0 +1,25 @@ + static FontInfo *DefaultFont; + +private: + + UTF16String name; + + int width,height; + bool bold,italic; + +protected: + + UTF16String &GetName(){return name;} + void SetName(UTF16String &); + + int GetWidth(){return width;} + int GetHeight(){return height;} + bool GetBold(){return bold;} + bool GetItalic(){return italic;} + + void SetWidth(int); + void SetHeight(int); + void SetBold(bool); + void SetItalic(bool); + + void InitPrivate(); diff --git a/inc/hgl/graph/text/FontInfo.h b/inc/hgl/graph/text/FontInfo.h new file mode 100644 index 00000000..491023a4 --- /dev/null +++ b/inc/hgl/graph/text/FontInfo.h @@ -0,0 +1,51 @@ +#ifndef HGL_FONT_INFO_INCLUDE +#define HGL_FONT_INFO_INCLUDE + +#include +#include +#include +namespace hgl +{ + /** + * 字体数据结构
+ * 用于记录字体名称,粗体,斜体,下划线等等信息 + */ + class FontInfo ///字体数据结构 + { + #include + + public: //属性 + + Property Name; ///<字体名称 + + Property Width; ///<平均字体宽度 + Property Height; ///<字体高度 + + Property Bold; ///<是否粗体 + Property Italic; ///<是否斜体 + + public: //事件 + + DefEvent(void,OnChange,(FontInfo *)); ///<字体改变事件 + + public: //方法 + + FontInfo(); + FontInfo(const FontInfo &); + FontInfo(const UTF16String &,int,int,bool=false,bool=false); + + static void SetDefaultFont(const UTF16String &,int,int,bool,bool); ///<设置缺省字体 + static void SetDefaultFont(const FontInfo &); ///<设置缺省字体 + static void ClearDefaultFont(); ///<清除缺省字体 + + void Set(const UTF16String &,int,int,bool=false,bool=false); ///<设置字体 + + public: //操作符重载 + + bool operator == (const FontInfo &); + bool operator != (const FontInfo &); + + void operator = (const FontInfo &); + };//class FontInfo +}//namespace hgl +#endif//HGL_FONT_INFO_INCLUDE diff --git a/inc/hgl/graph/text/FontSource.h b/inc/hgl/graph/text/FontSource.h new file mode 100644 index 00000000..6ab82a70 --- /dev/null +++ b/inc/hgl/graph/text/FontSource.h @@ -0,0 +1,50 @@ +#ifndef HGL_GRAPH_FONT_SOURCE_INCLUDE +#define HGL_GRAPH_FONT_SOURCE_INCLUDE + +#include +namespace hgl +{ + namespace graph + { + /** + * 字体数据源抽像基类
+ * 主要提供点阵字体的数据产生管理 + */ + class FontSource + { + public: + + /** + * 字体位图数据 + */ + struct Bitmap + { + int x,y; //图像显示偏移 + int w,h; //图像尺寸 + + int adv_x,adv_y;//字符尺寸 + + unsigned char *data; + };//struct Bitmap + + protected: + + FontInfo fnt; + + FontSource::Bitmap char_bitmap[0xFFFF]; ///<字符位图数据 + + protected: + + virtual bool MakeCharBitmap(u16char)=0; ///<产生字体数据 + virtual int GetLineHeight()const=0; ///<取得行高 + + public: + + FontSource(const FontInfo &); + virtual ~FontSource(); + + FontSource::Bitmap *GetCharBitmap(u16char); ///<取得字体数据 + };//class FontSource + }//namespace graph +}//namespace hgl +#endif//HGL_GRAPH_FONT_SOURCE_INCLUDE diff --git a/inc/hgl/graph/text/TileFont.h b/inc/hgl/graph/text/TileFont.h new file mode 100644 index 00000000..3d2255cc --- /dev/null +++ b/inc/hgl/graph/text/TileFont.h @@ -0,0 +1,175 @@ +#ifndef HGL_GRAPH_TILE_FONT_INCLUDE +#define HGL_GRAPH_TILE_FONT_INCLUDE + +#include +#include +#include +#include +#include +#include +#include +namespace hgl +{ + namespace graph + { + struct FontInfo; + class Renderable; + class Material; + + /** + * 使用每个Tile代表一个字符的管理模块
+ * 即可以使用系统字体,由程序实时生成字符;也可以使用由美术制作好的字体图片。 + */ + class TileFont ///Tile字体 + { + protected: + + TileData *tile_data; /// fud; ///<字体缓冲管理 + + uint8 *char_bitmap_buffer; ///<字符位图缓冲区 + uint char_bitmap_bytes; ///<字符位图字节数 + + VB2f *vertex2d; ///<绘制用顶点坐标 + VB2f *tex_coord; ///<绘制用顶点坐标 +// VB1ui *vertex_color; ///<绘制用顶点色 + Material *fnt_mtl; ///<绘制用材质 + Renderable *fnt_draw; ///<绘制用对象 + + int tile_width,tile_height; ///<所使用的Tile宽高 + int font_height; + int line_distance; + + protected: + + void Clear(const u16char &,TileData::Object *&); ///<清除某个字 + + FontSource::Bitmap *GetCharBitmap(const u16char &ch) ///<取得字符位图数据 + {return ((ch<=0xFF?eng_source:chs_source)->GetCharBitmap(ch));} + + FontSource::Bitmap *MakeCharBitmap(const u16char &ch); ///<生成字符位图数据 + + TileData::Object *GetCharData(const u16char &); ///<取得字符数据 + + bool MakeupText(Makeup &,int,int,const u16char *,int); ///<排版字符串 + + public: + + int GetHeight ()const {return font_height;} ///<取得字符高度 + int GetLineDistance ()const {return line_distance;} ///<取得行间距 + + void SetLineDistance(int n) {line_distance=n;} + + public: //属性 + + Color4f Color; ///<颜色 + + public: + + TileFont(int,TileData *,FontSource *,FontSource *); + virtual ~TileFont(); + + float CharWidth(u16char); ///<指定字符宽度 + float GetStringWidth(const u16char *,int=-1); ///<求字符串宽度 + + public: + + bool MakeupText(Makeup &,const u16char *,int=-1); ///<排版字符串 + bool MakeupText(Makeup &,const u16char *,int,TextAlignment); ///<排版字符串 + + void Draw(const Matrix4f *,const Makeup &,int=-1); ///<根据排版进行绘制 + + void Draw(float l,float t,const Makeup &makeup,int limit_char=-1) ///<根据排版进行绘制 + { + const Matrix4f mat=translate(l,t,0); + + Draw(&mat,makeup,limit_char); + } + + /** + * 绘制一个字符串,可限制字数,并且处理\n + * @param mat modelview变换矩阵 + * @param str 字符串 + * @param limit_char 限制的字数,-1表示不限制 + * @return 字符串的象素级宽度 + * @return <0 错误 + */ + float DrawString(const Matrix4f *mat,const u16char *str,int limit_char=-1) ///<绘制一个字符串,可限制字数,并且处理\n + { + Makeup m; + + if(!MakeupText(m,str,limit_char)) + return(-1); + + Draw(mat,m,limit_char); + + return m.Width; + } + + /** + * 绘制一个字符串,可限制字数,并且处理\n + * @param x X坐标 + * @param y Y坐标 + * @param str 字符串 + * @param limit_char 限制的字数,-1表示不限制 + * @return 字符串的象素级宽度 + * @return <0 错误 + */ + float DrawString(float x,float y,const u16char *str,int limit_char=-1) ///<绘制一个字符串,可限制字数,并且处理\n + { + const Matrix4f mat=translate(x,y,0); + + return DrawString(&mat,str,limit_char); + } + + float DrawFormat(const Matrix4f *mat,const u16char *,...); ///<绘制一个格式化的字符串 + float DrawFormat(float,float,const u16char *,...); ///<绘制一个格式化的字符串 + };//class TileFont + + TileFont *CreateTileFont(const FontInfo &,const FontInfo &,int=-1); ///<创建一个字体,使用系统字体 + + /** + * 通过系统字体创建一个Tile字体 + * @param chs_fontname 中文字体名称 + * @param eng_fontname 英文字体名称 + * @param width 宽,可以为0,表示默认。 + * @param height 高 + * @param bold 加粗,默认false + * @param italic 斜体,默认false + * @param anti 是否抗矩齿,默认true + * @param count 缓冲区内保存的字符个数 + */ + TileFont *CreateTileFont(const u16char *chs_fontname,const u16char *eng_fontname,int width,int height,bool bold=false,bool italic=false,bool anti=true,int count=-1); + + /** + * 通过系统字体创建一个Tile字体,中英文字体相同 + * @param fontname 字体名称 + * @param width 宽,可以为0,表示默认。 + * @param height 高 + * @param bold 加粗,默认false + * @param italic 斜体,默认false + * @param anti 是否抗矩齿,默认true + * @param count 缓冲区内保存的字符个数 + */ + __inline TileFont *CreateTileFont(const u16char *fontname,int width,int height,bool bold=false,bool italic=false,bool anti=true,int count=-1) + { + return CreateTileFont(fontname,fontname,width,height,bold,italic,anti,count); + } + + /** + * 通过系统字体创建一个Tile字体,无斜体,无加粗 + * @param chs_fontname 中文字体名称 + * @param eng_fontname 英文字体名称 + * @param width 宽,可以为0,表示默认。 + * @param height 高 + * @param count 缓冲区内保存的字符个数 + */ + __inline TileFont *CreateTileFont(const u16char *chs_fontname,const u16char *eng_fontname,int width,int height,int count=-1) + { + return CreateTileFont(chs_fontname,eng_fontname,width,height,false,false,true,count); + } + }//namespace graph +}//namespace hgl +#endif//HGL_GRAPH_TILE_FONT_INCLUDE diff --git a/inc/hgl/graph/vulkan/VK.h b/inc/hgl/graph/vulkan/VK.h index 9cbf87b3..f324c855 100644 --- a/inc/hgl/graph/vulkan/VK.h +++ b/inc/hgl/graph/vulkan/VK.h @@ -104,5 +104,11 @@ inline void debug_out(const hgl::List &extension_properti ++ep; } } + + void InitVulkanProperties(); +const List & GetLayerProperties(); +const List & GetExtensionProperties(); +const bool CheckLayerSupport(const char *); + VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_INCLUDE diff --git a/inc/hgl/graph/vulkan/VKDebugOut.h b/inc/hgl/graph/vulkan/VKDebugOut.h new file mode 100644 index 00000000..bd4f974e --- /dev/null +++ b/inc/hgl/graph/vulkan/VKDebugOut.h @@ -0,0 +1,23 @@ +#ifndef HGL_GRAPH_VULKAN_DEBUG_OUT_INCLUDE +#define HGL_GRAPH_VULKAN_DEBUG_OUT_INCLUDE + +#include + +VK_NAMESPACE_BEGIN + +class VKDebugOut +{ + VkInstance inst=nullptr; + + VkDebugUtilsMessengerEXT debug_messenger; + VkDebugReportCallbackEXT debug_report_callback; + +public: + + VKDebugOut(); + virtual ~VKDebugOut(); + + virtual bool Init(VkInstance); +};//class VKDebugOut +VK_NAMESPACE_END +#endif//HGL_GRAPH_VULKAN_DEBUG_OUT_INCLUDE diff --git a/inc/hgl/graph/vulkan/VKInstance.h b/inc/hgl/graph/vulkan/VKInstance.h index 0a98a5bf..0d8588d0 100644 --- a/inc/hgl/graph/vulkan/VKInstance.h +++ b/inc/hgl/graph/vulkan/VKInstance.h @@ -5,17 +5,14 @@ #include #include #include +#include VK_NAMESPACE_BEGIN class Instance { VkInstance inst; - List layer_properties; - List extension_properties; - - VkDebugUtilsMessengerEXT debug_messenger; - VkDebugReportCallbackEXT debug_report_callback; + VKDebugOut *debug_out; CharPointerList ext_list; @@ -23,9 +20,9 @@ VK_NAMESPACE_BEGIN private: - friend Instance *CreateInstance(const UTF8String &app_name); + friend Instance *CreateInstance(const UTF8String &app_name,VKDebugOut *do=nullptr); - Instance(VkInstance,CharPointerList &); + Instance(VkInstance,VKDebugOut *,CharPointerList &); public: @@ -33,13 +30,11 @@ VK_NAMESPACE_BEGIN operator VkInstance (){return inst;} - const List & GetLayerProperties ()const {return layer_properties;} - const bool CheckLayerSupport (const UTF8String &)const; const CharPointerList & GetExtList ()const {return ext_list;} const ObjectList &GetDeviceList ()const {return physical_devices;} const PhysicalDevice * GetDevice (VkPhysicalDeviceType)const; };//class Instance - Instance *CreateInstance(const UTF8String &); ///<创建一个Vulkan实例 + Instance *CreateInstance(const UTF8String &,VKDebugOut *do=nullptr); ///<创建一个Vulkan实例 VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_INSTANCE_INCLUDE diff --git a/inc/hgl/input/Event.h b/inc/hgl/input/Event.h new file mode 100644 index 00000000..61ab1c38 --- /dev/null +++ b/inc/hgl/input/Event.h @@ -0,0 +1,68 @@ +#pragma once +#include +namespace hgl +{ + namespace device_input + { + #pragma pack(push,1) + union InputEvent + { + struct + { + uint8 key; + }key_push; + + struct + { + uint8 key; + }key_pop; + + struct + { + uint16 x, y; + }mouse_move; + + struct + { + uint8 key; + }mouse_key_push; + + struct + { + uint8 key; + }mouse_key_pop; + + struct + { + int16 x, y; + }mouse_wheel; + + struct + { + int8 x, y; + }joystick_axis; + + struct + { + uint8 key; + }joystick_key_push; + + struct + { + uint8 key; + }joystick_key_pop; + + struct + { + uint16 x, y; + uint16 power; + }wacom; + + struct + { + u16char ch; + }char_input; + };//union InputEvent + #pragma pack(pop) + }//namespace device_input +}//namespace hgl diff --git a/res/shader/test.geom b/res/shader/test.geom new file mode 100644 index 00000000..c8f3cf27 --- /dev/null +++ b/res/shader/test.geom @@ -0,0 +1,15 @@ +#version 450 core + +layout(binding = 0) uniform WorldMatrix +{ + mat4 two_dim; + mat4 projection; + mat4 modelview; + mat4 mvp; + mat3 normal; +} world; + +void main() +{ + gl_Position=vec4(1.0)*world.mvp; +} diff --git a/src/RenderDevice/Vulkan/CMakeLists.txt b/src/RenderDevice/Vulkan/CMakeLists.txt index e2daa1d2..ef118125 100644 --- a/src/RenderDevice/Vulkan/CMakeLists.txt +++ b/src/RenderDevice/Vulkan/CMakeLists.txt @@ -2,6 +2,7 @@ SET(RENDER_DEVICE_VULKAN_SOURCE VKFormat.cpp VKMemory.cpp + VKProperties.cpp VKInstance.cpp VKPhysicalDevice.cpp VKImageView.cpp diff --git a/src/RenderDevice/Vulkan/VKDebugOut.cpp b/src/RenderDevice/Vulkan/VKDebugOut.cpp new file mode 100644 index 00000000..723f40f9 --- /dev/null +++ b/src/RenderDevice/Vulkan/VKDebugOut.cpp @@ -0,0 +1,171 @@ +#include +#include + +VK_NAMESPACE_BEGIN +namespace +{ + VkResult CreateDebugUtilsMessengerEXT(VkInstance instance,const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,const VkAllocationCallbacks *pAllocator,VkDebugUtilsMessengerEXT *pDebugMessenger) + { + auto func=(PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance,"vkCreateDebugUtilsMessengerEXT"); + if(func) + { + return func(instance,pCreateInfo,pAllocator,pDebugMessenger); + } + else + { + return VK_ERROR_EXTENSION_NOT_PRESENT; + } + } + + void DestroyDebugUtilsMessengerEXT(VkInstance instance,VkDebugUtilsMessengerEXT debugMessenger,const VkAllocationCallbacks *pAllocator) + { + auto func=(PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance,"vkDestroyDebugUtilsMessengerEXT"); + if(func) + { + func(instance,debugMessenger,pAllocator); + } + } + + VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,VkDebugUtilsMessageTypeFlagsEXT messageType,const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,void *pUserData) + { + if(messageSeverity&VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) + { + std::cout<<"ERROR: "<pMessage<pMessage<pMessage<pMessage<pMessage<pMessage<pMessage<pMessage<pMessage<pMessage<Init(inst); + return(new Instance(inst,ext_list,do)); + } return(nullptr); } -Instance::Instance(VkInstance i,CharPointerList &el) +Instance::Instance(VkInstance i,CharPointerList &el,VKDebugOut *do) { inst=i; ext_list=el; - { - uint32_t layerCount; - vkEnumerateInstanceLayerProperties(&layerCount,nullptr); - - layer_properties.SetCount(layerCount); - vkEnumerateInstanceLayerProperties(&layerCount,layer_properties.GetData()); - - debug_out(layer_properties); - } - - { - uint32_t prop_count; - vkEnumerateInstanceExtensionProperties(nullptr,&prop_count,nullptr); - - extension_properties.SetCount(prop_count); - vkEnumerateInstanceExtensionProperties(nullptr,&prop_count,extension_properties.GetData()); - - debug_out(extension_properties); - } - - debug_report_callback=VK_NULL_HANDLE; - { - VkDebugReportCallbackCreateInfoEXT create_info; - - create_info.sType =VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; - create_info.pNext =nullptr; - - create_info.flags =VK_DEBUG_REPORT_ERROR_BIT_EXT - |VK_DEBUG_REPORT_WARNING_BIT_EXT - |VK_DEBUG_REPORT_DEBUG_BIT_EXT - |VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; - - create_info.pfnCallback =dbgFunc; - create_info.pUserData =nullptr; - - CreateDebugReportCallbackEXT(inst,&create_info,nullptr,&debug_report_callback); - } - - debug_messenger=VK_NULL_HANDLE; - { - VkDebugUtilsMessengerCreateInfoEXT createInfo; - - createInfo.sType =VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; - createInfo.pNext =nullptr; - createInfo.flags =0; - - createInfo.messageSeverity =VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT - |VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT - |VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; - - createInfo.messageType =VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT - |VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT - |VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; - - createInfo.pfnUserCallback =debugCallback; - createInfo.pUserData =nullptr; - - CreateDebugUtilsMessengerEXT(inst,&createInfo,nullptr,&debug_messenger); - } + debug_out=do; uint32_t gpu_count = 1; @@ -260,34 +72,13 @@ Instance::Instance(VkInstance i,CharPointerList &el) } Instance::~Instance() -{ + + SAFE_CLEAR(debug_out); + physical_devices.Clear(); - - if(debug_messenger) - DestroyDebugUtilsMessengerEXT(inst,debug_messenger,nullptr); - - if(debug_report_callback) - DestroyDebugReportCallbackEXT(inst,debug_report_callback,nullptr); - vkDestroyInstance(inst,nullptr); } -const bool Instance::CheckLayerSupport(const UTF8String &layer_name)const -{ - const uint32_t count=layer_properties.GetCount(); - VkLayerProperties *lp=layer_properties.GetData(); - - for(uint32_t i=0;ilayerName) - return(true); - - ++lp; - } - - return(false); -} - const PhysicalDevice *Instance::GetDevice(VkPhysicalDeviceType type)const { const uint32_t count=physical_devices.GetCount(); diff --git a/src/RenderDevice/Vulkan/VKProperties.cpp b/src/RenderDevice/Vulkan/VKProperties.cpp new file mode 100644 index 00000000..6be018f8 --- /dev/null +++ b/src/RenderDevice/Vulkan/VKProperties.cpp @@ -0,0 +1,58 @@ +#include + +VK_NAMESPACE_BEGIN + +namespace +{ + static List layer_properties; + static List extension_properties; +}//namespace + +const List &GetLayerProperties(){return layer_properties;} +const List &GetExtensionProperties(){return extension_properties;} + +void InitVulkanProperties() +{ + layer_properties.Clear(); + extension_properties.Clear(); + + { + uint32_t layer_count; + vkEnumerateInstanceLayerProperties(&layer_count,nullptr); + + layer_properties.SetCount(layer_count); + vkEnumerateInstanceLayerProperties(&layer_count,layer_properties.GetData()); + + debug_out(layer_properties); + } + + { + uint32_t prop_count; + vkEnumerateInstanceExtensionProperties(nullptr,&prop_count,nullptr); + + extension_properties.SetCount(prop_count); + vkEnumerateInstanceExtensionProperties(nullptr,&prop_count,extension_properties.GetData()); + + debug_out(extension_properties); + } +} + +const bool CheckLayerSupport(const char *layer_name) +{ + if(!layer_name||!*layer_name) + return(false); + + const uint32_t count=layer_properties.GetCount(); + VkLayerProperties *lp=layer_properties.GetData(); + + for(uint32_t i=0;ilayerName)==0) + return(true); + + ++lp; + } + + return(false); +} +VK_NAMESPACE_END diff --git a/src/Tools/ShaderCompiler/CMakeLists.txt b/src/Tools/ShaderCompiler/CMakeLists.txt new file mode 100644 index 00000000..ef30c091 --- /dev/null +++ b/src/Tools/ShaderCompiler/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(ShaderCompiler main.cpp) +target_link_libraries((ShaderCompiler PRIVATE ${ULRE} \ No newline at end of file diff --git a/src/Tools/ShaderCompiler/main.cpp b/src/Tools/ShaderCompiler/main.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/Tools/TexConv/CMakeLists.txt b/src/Tools/TexConv/CMakeLists.txt new file mode 100644 index 00000000..e69fbb39 --- /dev/null +++ b/src/Tools/TexConv/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(TexConv MainUnit.cpp ${HGL_GRAPHICS_MAIN_SOURCE}) + +target_compile_definitions(TexConv PRIVATE "-DIL_STATIC_LIB") +target_include_directories(TexConv PRIVATE ${CMGDK_PATH}/src/PlugIn/Image.Monolayer/DevIL/include) +target_link_libraries(TexConv ${HGL_GRAPHICS_LIB} DevIL) + +SET_TARGET_PROPERTIES(TexConv PROPERTIES WIN32_EXECUTABLE "true") diff --git a/src/Tools/TexConv/MainUnit.cpp b/src/Tools/TexConv/MainUnit.cpp new file mode 100644 index 00000000..8619c008 --- /dev/null +++ b/src/Tools/TexConv/MainUnit.cpp @@ -0,0 +1,708 @@ +#include + +#include //SetClearColor +#include //GLSL +#include //Texture +#include //Material +#include //VB3f/VB4f +#include //Renderable +#include //GetMicroTime + +#include +#include +#include +#include +#include //GetString + +#include +#include + +#include + +using namespace hgl; +using namespace hgl::io; +using namespace hgl::util; +using namespace hgl::graph; +using namespace hgl::filesystem; + +const TextureFormat *default_r8 =&TextureFormatInfoList[HGL_SF_R8]; +const TextureFormat *default_rg8 =&TextureFormatInfoList[HGL_SF_RG8]; +const TextureFormat *default_rgb8 =&TextureFormatInfoList[HGL_SF_RGB8]; +const TextureFormat *default_rgba8 =&TextureFormatInfoList[HGL_SF_RGBA8]; + +const TextureFormat *default_r16 =&TextureFormatInfoList[HGL_SF_R16]; +const TextureFormat *default_r32f =&TextureFormatInfoList[HGL_SF_R32F]; +//-------------------------------------------------------------------------------------------------- +const TextureFormat * glfmt[4] ={NULL,NULL,NULL,NULL}; //选中格式 + bool gen_mipmaps =false; //是否产生mipmaps + + bool only_view =false; //仅显示 + + bool use_color_key=false; //是否使用ColorKey + uint8 color_key[3]; //ColorKey颜色 + +const float texcoord[] ={0.0f,0.0f, 1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f, 0.0f,1.0f}; + + VertexArray * va =NULL; + Renderable * render_obj =NULL; + Material * mtl =NULL; + Texture2D * tex =NULL; + VB2f * vertex =NULL; +//-------------------------------------------------------------------------------------------------- +//OpenIL数据 + +uint il_index=0; //图片索引 +int il_width,il_height,il_bit; +uint il_format=0; +uint il_type=0; +uint il_pal_type=0; +uint il_pal_color_num=0; +//-------------------------------------------------------------------------------------------------- +//统计数据 + +int max_pixels=0; //最大像素数 +uint8 *image_data=NULL; //图像数据 + +int max_bytes=0; //最大字节数 +uint8 *texture_data=NULL; //贴图数据 + +int convert_count=0; //转换总数 +int bytes_count=0; //总字节数 +int cbytes_count=0; //转换后总字节数 +//-------------------------------------------------------------------------------------------------- +const TextureFormat *CheckOpenGLCoreFormat(const CmdParse &cmd,const os_char *flag,const TextureFormat *default_tf) +{ + OSString fmtstr; + + if(!cmd.GetString(flag,fmtstr))return(nullptr); + +#if HGL_OS==HGL_OS_Windows + UTF8String str=to_u8(fmtstr); + + const TextureFormat *result=GetTextureFormat(str.c_str()); +#else + const TextureFormat *result=GetTextureFormat(fmtstr.c_str()); +#endif//HGL_OS==HGL_OS_Windows + + if(result)return(result); + + return default_tf; +} + +void CheckOpenGLCoreFormat(const CmdParse &cmd) +{ + //指定格式 + glfmt[0]=CheckOpenGLCoreFormat(cmd,OS_TEXT("/R:"), &TextureFormatInfoList[HGL_SF_R8]); + glfmt[1]=CheckOpenGLCoreFormat(cmd,OS_TEXT("/RG:"), &TextureFormatInfoList[HGL_SF_RG8]); + glfmt[2]=CheckOpenGLCoreFormat(cmd,OS_TEXT("/RGB:"), &TextureFormatInfoList[HGL_SF_RGB8]); + glfmt[3]=CheckOpenGLCoreFormat(cmd,OS_TEXT("/RGBA:"), &TextureFormatInfoList[HGL_SF_RGBA8]); +} + +void CheckColorKey(const CmdParse &cmd) +{ + OSString ckstr; + + if(!cmd.GetString(OS_TEXT("/ColorKey:"),ckstr))return; + + os_char rgbstr[6]; + + hgl_cpy(rgbstr,ckstr.c_str(),6); //注意:hgl_cpy是跨类型复制的,不要替换成strcpy或memcpy + + ParseHexStr(color_key[0],rgbstr+0); + ParseHexStr(color_key[1],rgbstr+2); + ParseHexStr(color_key[2],rgbstr+4); + + use_color_key=true; +} + +bool CheckSameAlpha(uint8 *data,uint count) +{ + uint8 *p=data; + + while(count--) + { + if(*p!=*data)return(false); + + p++; + } + + return(true); +} + +/** +* 检测RGB数据是否一致 +*/ +bool CheckSameRGB(uint8 *data,int color,uint count) +{ + uint8 *p=data; + + while(count--) + { + if(memcmp(data,p,color-1)) + return(false); + + p+=color; + } + + return(true); +} + +void MixLA(uint8 *lum,uint8 *alpha,int size) +{ + int i; + + for(i=0;iWrite("Tex\x1A",4); + dos->WriteUint8(1); //版本号 + dos->WriteBool(false); //是否有mipmaps + dos->Write(fmt_str,16); //格式 + dos->WriteUint32(bytes); //字节数 + + if(include_color_key) + { + dos->WriteBool(true); + dos->WriteUint8(color_key,3); + + LOG_INFO(OS_TEXT("\tColor Key: true")); + } + else + { + dos->Write("\0\0\0\0",4); + } + + dos->WriteUint32(width); //宽 + dos->WriteUint32(height); //高 + + dos->Write(texture_data,bytes); + delete dos; + + LOG_INFO(OS_TEXT("\tSave to ")+OSString(tex_fn)); +} + +int ConvertImage(const os_char *filename) +{ + bool confirm_color_key=false; + + uint pixels=0; + const TextureFormat *curfmt=nullptr; + const TextureFormat *tarfmt=nullptr; + + LOG_INFO(OS_TEXT("File: ")+OSString(filename)); + + ilGenImages(1,&il_index); + ilBindImage(il_index); + + if(ilLoadImage(filename)) + { + il_width =ilGetInteger(IL_IMAGE_WIDTH); + il_height =ilGetInteger(IL_IMAGE_HEIGHT); + il_bit =ilGetInteger(IL_IMAGE_BITS_PER_PIXEL); + il_format =ilGetInteger(IL_IMAGE_FORMAT); + il_type =ilGetInteger(IL_IMAGE_TYPE); + + if(ilGetInteger(IL_IMAGE_ORIGIN)==IL_ORIGIN_LOWER_LEFT) + iluFlipImage(); + + LOG_INFO(OS_TEXT("\twidth: ")+OSString(il_width)); + LOG_INFO(OS_TEXT("\theight: ")+OSString(il_height)); + + pixels=il_width*il_height; + + if(pixels>max_pixels) + SAFE_CLEAR_ARRAY(image_data); + + if(!image_data) + { + image_data=new uint8[pixels*4*4]; + max_pixels=pixels; + } + + if(il_format!=IL_COLOR_INDEX) + { + if(il_format==IL_LUMINANCE ) + { + if(il_type==IL_UNSIGNED_BYTE) + curfmt=default_r8; + else + if(il_type==IL_UNSIGNED_SHORT) + curfmt=default_r16; + else + if(il_type==IL_FLOAT) + curfmt=default_r32f; + else + { + ilConvertImage(IL_LUMINANCE,IL_UNSIGNED_BYTE); + il_type=IL_UNSIGNED_BYTE; + + curfmt=default_r8; + } + + tarfmt=(glfmt[0]?glfmt[0]:curfmt); + + memcpy(image_data,ilGetData(),pixels*curfmt->source_bytes); + } + else + { + if(il_type!=IL_UNSIGNED_BYTE) + { + ilConvertImage(il_format,IL_UNSIGNED_BYTE); + il_type=IL_UNSIGNED_BYTE; + } + + ConvertPixelFormat(); + + if(il_format==IL_LUMINANCE ) + { + curfmt=default_r8; + tarfmt=(glfmt[0]?glfmt[0]:curfmt); + + memcpy(image_data,ilGetData(),pixels); + } + else + if(il_format==IL_ALPHA ) + { + curfmt=default_r8; + tarfmt=(glfmt[0]?glfmt[0]:curfmt); + + memcpy(image_data,ilGetAlpha(GL_UNSIGNED_BYTE),pixels); + } + else + if(il_format==IL_LUMINANCE_ALPHA) + { + curfmt=default_rg8; + tarfmt=(glfmt[1]?glfmt[1]:curfmt); + + uint8 *alpha=ilGetAlpha(GL_UNSIGNED_BYTE); + + memcpy(image_data,ilGetData(),pixels*2); + + MixLA(image_data,alpha,pixels); + + free(alpha); + } + else + if(il_format==IL_RGB ) + { + curfmt=default_rgb8; + tarfmt=(glfmt[2]?glfmt[2]:curfmt); + + memcpy(image_data,ilGetData(),pixels*3); + + if(use_color_key) //检测ColorKey是否存在 + { + unsigned char *p=image_data; + + for(int i=0;iSetImage(il_width,il_height,image_data,pixels*curfmt->source_bytes,curfmt->tsf,tarfmt->video_format); + + #if HGL_OS == HGL_OS_Windows + LOG_INFO(OS_TEXT("\tcolor format = ")+to_u16(curfmt->name)+OS_TEXT(" bytes = ")+OSString(curfmt->source_bytes*il_width*il_height)); + LOG_INFO(OS_TEXT("\ttarget format = ")+to_u16(tarfmt->name)); + #else + LOG_INFO(OS_TEXT("\tcolor format = ")+OSString(curfmt->name)+OS_TEXT(" bytes = ")+OSString(curfmt->source_bytes*il_width*il_height)); + LOG_INFO(OS_TEXT("\ttarget format = ")+OSString(tarfmt->name)); + #endif//HGL_OS == HGL_OS_Windows + + int bytes=tex->GetImage(NULL,tarfmt->tsf); + + if(bytes>0) + { + LOG_INFO(OS_TEXT("\toutput bytes = ")+OSString(bytes)); + + if(bytes>max_bytes) + SAFE_CLEAR_ARRAY(texture_data); + + if(!texture_data) + { + texture_data=new uint8[bytes]; + max_bytes=bytes; + } + + tex->GetImage(texture_data,tarfmt->tsf); + + SaveTexture2DToFile(filename,texture_data,il_width,il_height,tarfmt->name,bytes,confirm_color_key); + + convert_count++; + bytes_count+=il_width*il_height*curfmt->source_bytes; + cbytes_count+=bytes; + } + } +// else //索引色贴图 +// { +// il_pal_type =ilGetInteger(IL_PALETTE_TYPE); //调色板类型 +// il_pal_color_num=ilGetInteger(IL_PALETTE_NUM_COLS); //颜色数量 +// +// LOG_INFO(OS_TEXT("\tpal color number = ")+OSString(il_pal_color_num)); +// +// if(il_pal_color_num==16||il_pal_color_num==256) +// { +// CheckPalette(); +// +// if(il_pal_type==IL_PAL_RGB24 &&il_pal_color_num== 16)curfmt=GetFormat("16RGB");else +// +// if(il_pal_type==IL_PAL_RGBA32&&il_pal_color_num== 16)curfmt=GetFormat("16RGBA");else +// if(il_pal_type==IL_PAL_RGB24 &&il_pal_color_num==256)curfmt=GetFormat("256RGB");else +// if(il_pal_type==IL_PAL_RGBA32&&il_pal_color_num==256)curfmt=GetFormat("256RGBA");else +// curfmt=NULL; +// +// if(curfmt) +// LOG_INFO(OS_TEXT("\tcolor format = ")+OSString(curfmt->name)); +// } +// else +// curfmt=NULL; +// } + + if(!curfmt) + LOG_INFO("\tformat error!\n"); + } + else + { + LOG_INFO("\tLoad File error!"); + } + + ilDeleteImages(1,&il_index); + return(0); +} + +class EnumFileConfigApp:public EnumFileConfig +{ +public: + + GraphicsApplication *app; + + using EnumFileConfig::EnumFileConfig; +}; + +void EnumConvertImage(EnumFileConfig *efc,FileInfo &fi) +{ + EnumFileConfigApp *efca=(EnumFileConfigApp *)efc; + + GraphicsApplication *gapp=efca->app; + + ConvertImage(fi.fullname); + + render_obj->AutoCreateShader(); + + ClearColorDepthBuffer(); + + const int l=(GetScreenWidth()-il_width)/2; + const int t=(GetScreenHeight()-il_height)/2; + + vertex->Begin(); + vertex->WriteRect(l,t,il_width,il_height); + vertex->End(); + + DirectRender2D(render_obj); + + gapp->SwapBuffer(); + gapp->WaitActive(); +} + +HGL_GRAPHICS_MAIN(sii,app,args) +{ + CmdParse cmd(args); + + bool sub=false; + + sii.info.ProjectName=U8_TEXT("贴图转换"); + sii.info.ProjectCode=OS_TEXT("Texture Converter"); + sii.info.ProjectVersion=U8_TEXT("1.01"); + + if(!app.Init(&sii))return(-1); + + LOG_INFO("argc="+UTF8String(args.GetCount())); + for(int i=0;i [/s] [/view] [/R:?] [/RG:?] [/RGB:?] [/RGBA:?]\n" + "\n" + "Params:\n" + "\t/s : proc sub-directory\n" + "\n" + "support format:\n\n"); + + int count=0; + int len; + memset(space,' ',32); + space[32]=0; + + for(int i=HGL_SF_NONE+1;iSetVertexBuffer(vbtVertex,vertex=new VB2f(6,0,HGL_DYNAMIC_DRAW)); + va->SetVertexBuffer(vbtDiffuseTexCoord,new VB2f(6,texcoord)); + + tex=CreateTexture2D(); + + mtl=new Material; + + mtl->SetColorMaterial(false); + mtl->SetTexture(mtcDiffuse,tex); + + render_obj=new Renderable(va,mtl); + + render_obj->SetMaterial(mtl); + render_obj->SetTexCoord(mtcDiffuse,vbtDiffuseTexCoord); + + double start_time=GetMicroTime(); + double end_time; + + EnumFileConfigApp efc; + + efc.app =&app; + + efc.folder_name =cur_path; + efc.find_name =args[0]; + efc.proc_file =true; + efc.sub_folder =sub; + efc.cb_file =EnumConvertImage; + + EnumFile(&efc); + + end_time=GetTime(); + + LOG_INFO(OS_TEXT("总计转换图片")+OSString(convert_count) + +OS_TEXT("张,总计处理原始数据")+OSString(bytes_count) + +OS_TEXT("字节,转换后")+OSString(cbytes_count) + +OS_TEXT("字节,总计耗时")+OSString(end_time-start_time)+OS_TEXT("秒")); + + delete[] image_data; + delete[] texture_data; + delete tex; + delete render_obj; + + ilShutDown(); + + return(0); +}