From 2df1b26a094a8cfaab9cbd5d1b1d6be33d754da8 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 9 Jan 2020 22:01:27 +0800 Subject: [PATCH] to update DataSource/Component of Material --- inc/hgl/graph/material/Component.h | 32 +++++---- inc/hgl/graph/material/DataSource.h | 104 +++++++++++++--------------- 2 files changed, 67 insertions(+), 69 deletions(-) diff --git a/inc/hgl/graph/material/Component.h b/inc/hgl/graph/material/Component.h index cbaf279b..09baee6c 100644 --- a/inc/hgl/graph/material/Component.h +++ b/inc/hgl/graph/material/Component.h @@ -15,6 +15,7 @@ BEGIN_MATERIAL_NAMESPACE ShadingModel=0, Color, + Mask, Opacity, Normal, @@ -35,7 +36,7 @@ BEGIN_MATERIAL_NAMESPACE BEGIN_RANGE =ShadingModel, END_RANGE =Anisotropy, RANGE_SIZE =END_RANGE-BEGIN_RANGE+1, - };// + };//enum class Component enum class ComponentBit { @@ -43,6 +44,7 @@ BEGIN_MATERIAL_NAMESPACE MC_BIT_DEFINE(ShadingModel ), MC_BIT_DEFINE(Color ), + MC_BIT_DEFINE(Mask ), MC_BIT_DEFINE(Opacity ), MC_BIT_DEFINE(Normal ), @@ -66,31 +68,37 @@ BEGIN_MATERIAL_NAMESPACE { Bool=0, Float, + Double, Int, Uint, - };// + };//enum class ComponentDataType enum class DataFormat { NONE=0, - #define MATERIAL_DATA_FORMAT_DEFINE(long_name,short_name,type) long_name =((uint(ComponentDataType)<<4)|1), \ - vec##short_name##1 =((uint(ComponentDataType)<<4)|2), \ - vec##short_name##2 =((uint(ComponentDataType)<<4)|3), \ - vec##short_name##3 =((uint(ComponentDataType)<<4)|4), + #define MATERIAL_DATA_FORMAT_DEFINE(short_name,type) type =((uint(ComponentDataType::type)<<4)|1), \ + Vector##2##short_name =((uint(ComponentDataType::type)<<4)|2), \ + Vector##3##short_name =((uint(ComponentDataType::type)<<4)|3), \ + Vector##4##short_name =((uint(ComponentDataType::type)<<4)|4) - MATERIAL_DATA_FORMAT_DEFINE(boolean,b,Bool ), - MATERIAL_DATA_FORMAT_DEFINE(float, f,Float ), - MATERIAL_DATA_FORMAT_DEFINE(int, i,Int ), - MATERIAL_DATA_FORMAT_DEFINE(uint, u,Uint ), + MATERIAL_DATA_FORMAT_DEFINE(b,Bool ), + MATERIAL_DATA_FORMAT_DEFINE(f,Float ), + MATERIAL_DATA_FORMAT_DEFINE(d,Double), + MATERIAL_DATA_FORMAT_DEFINE(i,Int ), + MATERIAL_DATA_FORMAT_DEFINE(u,Uint ), #undef MATERIAL_DATA_FORMAT_DEFINE - }; + };//enum class DataFormat + + inline const ComponentDataType GetFormatBaseType (const enum class DataFormat &df){return ComponentDataType(uint(df)>>4);} + inline const uint GetFormatChannels (const enum class DataFormat &df){return uint(df)&7;} using ComponentBitsConfig=uint32; constexpr ComponentBitsConfig MCC_PureColor =uint32(ComponentBit::Color); constexpr ComponentBitsConfig MCC_PureNormal =uint32(ComponentBit::Normal); + constexpr ComponentBitsConfig MCC_PureOpacity =uint32(ComponentBit::Opacity); constexpr ComponentBitsConfig MCC_ColorNormal =uint32(ComponentBit::Color)|uint32(ComponentBit::Normal); constexpr ComponentBitsConfig MCC_CNMR =uint32(ComponentBit::Color)|uint32(ComponentBit::Normal)|uint32(ComponentBit::Metallic)|uint32(ComponentBit::Roughness); @@ -100,7 +108,7 @@ BEGIN_MATERIAL_NAMESPACE ComponentDataType type; ///<数据类型 uint channels; ///<通道数 bool LinearColorspace; ///<是要求线性颜色空间 - }; + };//struct ComponentConfig const ComponentConfig *GetConfig(const enum class Component c); END_MATERIAL_NAMESPACE diff --git a/inc/hgl/graph/material/DataSource.h b/inc/hgl/graph/material/DataSource.h index b3ee8b26..c989dd6b 100644 --- a/inc/hgl/graph/material/DataSource.h +++ b/inc/hgl/graph/material/DataSource.h @@ -15,65 +15,14 @@ class DataSource public: - DataSource() - { - format=DataFormat::NONE; - } + const ComponentDataType GetDataType()const{return GetFormatBaseType(format);} ///<获取数据基本类型 + const uint GetChannels()const{return GetFormatChannels(format);} ///<获取数据通道数量 - DataSource(const DataFormat &df) - { - format=df; - } +public: + DataSource() {format=DataFormat::NONE;} + DataSource(const DataFormat &df){format=df;} virtual ~DataSource()=default; - - virtual bool SetX(UTF8String &,const UTF8String &)const{return false;} - virtual bool SetY(UTF8String &,const UTF8String &)const{return false;} - virtual bool SetZ(UTF8String &,const UTF8String &)const{return false;} - virtual bool SetW(UTF8String &,const UTF8String &)const{return false;} - - virtual bool SetXY(UTF8String &,const UTF8String &)const{return false;} - virtual bool SetYZ(UTF8String &,const UTF8String &)const{return false;} - virtual bool SetZW(UTF8String &,const UTF8String &)const{return false;} - - virtual bool SetXYZ(UTF8String &,const UTF8String &)const{return false;} - virtual bool SetXYZW(UTF8String &,const UTF8String &)const{return false;} - - bool SetR(UTF8String &result,const UTF8String &str)const{return this->SetX(result,str);} - bool SetG(UTF8String &result,const UTF8String &str)const{return this->SetY(result,str);} - bool SetB(UTF8String &result,const UTF8String &str)const{return this->SetZ(result,str);} - bool SetA(UTF8String &result,const UTF8String &str)const{return this->SetW(result,str);} - - bool SetRG(UTF8String &result,const UTF8String &str)const{return this->SetXY(result,str);} - bool SetGB(UTF8String &result,const UTF8String &str)const{return this->SetYZ(result,str);} - bool SetBA(UTF8String &result,const UTF8String &str)const{return this->SetZW(result,str);} - - bool SetRGB(UTF8String &result,const UTF8String &str)const{return this->SetXYZ(result,str);} - bool SetRGBA(UTF8String &result,const UTF8String &str)const{return this->SetXYZW(result,str);} - - virtual bool GetX(UTF8String &)const{return false;} - virtual bool GetY(UTF8String &)const{return false;} - virtual bool GetZ(UTF8String &)const{return false;} - virtual bool GetW(UTF8String &)const{return false;} - - virtual bool GetXY(UTF8String &)const{return false;} - virtual bool GetYZ(UTF8String &)const{return false;} - virtual bool GetZW(UTF8String &)const{return false;} - - virtual bool GetXYZ(UTF8String &)const{return false;} - virtual bool GetXYZW(UTF8String &)const{return false;} - - bool GetR(UTF8String &result)const{return this->GetX(result);} - bool GetG(UTF8String &result)const{return this->GetY(result);} - bool GetB(UTF8String &result)const{return this->GetZ(result);} - bool GetA(UTF8String &result)const{return this->GetW(result);} - - bool GetRG(UTF8String &result)const{return this->GetXY(result);} - bool GetGB(UTF8String &result)const{return this->GetYZ(result);} - bool GetBA(UTF8String &result)const{return this->GetZW(result);} - - bool GetRGB(UTF8String &result)const{return this->GetXYZ(result);} - bool GetRGBA(UTF8String &result)const{return this->GetXYZW(result);} };//class DataSource /** @@ -81,40 +30,81 @@ public: */ class DataSourceConst:public DataSource { +public: + + using DataSource::DataSource; };//class DataSourceConst:public DataSource /** - * Uniform数据源 + * Uniform 数据源 */ class DataSourceUniform:public DataSource { +public: + + using DataSource::DataSource; };//class DataSourceUniform:public DataSource +/** + * 函数数据源 + */ + class DataSourceFunction:public DataSource + { +public: + + using DataSource::DataSource; + };//class DataSourceFunction:public DataSource + /** * 纹理数据源 */ class DataSourceTexture:public DataSource { +public: + + using DataSource::DataSource; };//class DataSourceTexture:public DataSource class DataSourceTexture1D:public DataSourceTexture { +public: + + using DataSourceTexture::DataSourceTexture; };//class DataSourceTexture1D:public DataSourceTexture +class DataSourceTexture1DArrays:public DataSourceTexture +{ +public: + + using DataSourceTexture::DataSourceTexture; +};//class DataSourceTexture1DArrays:public DataSourceTexture + class DataSourceTexture2D:public DataSourceTexture { +public: + + using DataSourceTexture::DataSourceTexture; };//class DataSourceTexture2D:public DataSourceTexture class DataSourceTexture2DArrays:public DataSourceTexture { +public: + + using DataSourceTexture::DataSourceTexture; };//class DataSourceTexture2DArrays:public DataSourceTexture class DataSourceTextureCubemap:public DataSourceTexture { +public: + + using DataSourceTexture::DataSourceTexture; };//class DataSourceTextureCubemap:public DataSourceTexture class DataSourceTextureCubemapArrays:public DataSourceTexture { +public: + + using DataSourceTexture::DataSourceTexture; };//class DataSourceTextureCubemapArrays:public DataSourceTexture END_MATERIAL_NAMESPACE #endif//HGL_GRAPH_MATERIAL_DATA_SOURCE_INCLUDE