增加纹理封装
This commit is contained in:
parent
7cf879207f
commit
dda548dc6f
@ -85,8 +85,8 @@ constexpr float vertex_data[]={ -0.75f, 0.75f,
|
||||
constexpr float texcoord_data[]={ -0.25,-0.25,
|
||||
-0.25, 1.25,
|
||||
1.25,-0.25,
|
||||
1.25, 1.25 };
|
||||
|
||||
1.25, 1.25
|
||||
};
|
||||
|
||||
void BindVBO2VAO(const int vao,const int binding_index,const int shader_location,VertexBufferBase *vb)
|
||||
{
|
||||
|
@ -3,6 +3,15 @@
|
||||
|
||||
#include<iostream>
|
||||
#include<hgl/CodePage.h>
|
||||
|
||||
#if (HGL_COMPILER == HGL_COMPILER_GNU)||(HGL_COMPILER == HGL_COMPILER_LLVM)
|
||||
#define __HGL_FUNC__ __PRETTY_FUNCTION__
|
||||
#elif HGL_COMPILER == HGL_COMPILER_Microsoft
|
||||
#define __HGL_FUNC__ __FUNCSIG__
|
||||
#else
|
||||
#define __HGL_FUNC__ __FUNCTION__
|
||||
#endif//
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace logger
|
||||
|
53
inc/hgl/graph/Texture.h
Normal file
53
inc/hgl/graph/Texture.h
Normal file
@ -0,0 +1,53 @@
|
||||
#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
|
68
inc/hgl/graph/Texture1D.h
Normal file
68
inc/hgl/graph/Texture1D.h
Normal file
@ -0,0 +1,68 @@
|
||||
#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
|
61
inc/hgl/graph/Texture2D.h
Normal file
61
inc/hgl/graph/Texture2D.h
Normal file
@ -0,0 +1,61 @@
|
||||
#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
|
184
inc/hgl/graph/TextureData.h
Normal file
184
inc/hgl/graph/TextureData.h
Normal file
@ -0,0 +1,184 @@
|
||||
#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
|
146
inc/hgl/graph/TextureFormat.h
Normal file
146
inc/hgl/graph/TextureFormat.h
Normal file
@ -0,0 +1,146 @@
|
||||
#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
|
140
inc/hgl/graph/TextureSourceFormat.h
Normal file
140
inc/hgl/graph/TextureSourceFormat.h
Normal file
@ -0,0 +1,140 @@
|
||||
#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; //数据类型(指BYTE,SHORT,FLOAT这些)
|
||||
|
||||
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
|
@ -5,5 +5,10 @@
|
||||
VertexBuffer.cpp
|
||||
VertexBufferControlDSA.cpp
|
||||
VertexBufferControlBind.cpp
|
||||
OpenGLDebug.cpp)
|
||||
OpenGLDebug.cpp
|
||||
TextureFormat.cpp
|
||||
Texture1D.cpp
|
||||
Texture1DDSA.cpp
|
||||
Texture2D.cpp
|
||||
Texture2DDSA.cpp)
|
||||
|
||||
|
102
src/RenderDriver/Texture1D.cpp
Normal file
102
src/RenderDriver/Texture1D.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
#include<hgl/graph/Texture1D.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
bool Texture1D::SetImage(Texture1DData *ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("param error,ptr=nullptr"));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (!ptr->length)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("size error,image length=") + OSString(ptr->length));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
length = ptr->length;
|
||||
|
||||
video_format = ptr->GetVideoFormat();
|
||||
pixel_format = ptr->GetPixelFormat();
|
||||
|
||||
if (!_SetImage(ptr))
|
||||
{
|
||||
length=0;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
int Texture1D::GetImage(void *data_pointer, TSF fmt, int level)
|
||||
{
|
||||
if (!TextureSourceFormatCheck(fmt))
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("glTexture1D::GetImage,fmt error =") + OSString(fmt));
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return _GetImage(data_pointer,fmt,level);
|
||||
}
|
||||
|
||||
bool Texture1D::ChangeImage(uint s, uint l, void *data, uint bytes, TSF sf)
|
||||
{
|
||||
if (s >= length
|
||||
|| l>length - s
|
||||
|| !data
|
||||
|| !TextureSourceFormatCheck(sf))
|
||||
RETURN_FALSE;
|
||||
|
||||
return _ChangeImage(s,l,data,bytes,sf);
|
||||
}
|
||||
}//namespace graph
|
||||
|
||||
namespace graph
|
||||
{
|
||||
Texture1D *CreateTexture1DDSA();
|
||||
Texture1D *CreateTexture1DBind();
|
||||
|
||||
Texture1D *CreateTexture1D()
|
||||
{
|
||||
// if(GLEW_VERSION_4_5||GLEW_ARB_direct_state_access||GL_EXT_direct_state_access)
|
||||
return CreateTexture1DDSA();
|
||||
// else
|
||||
// return CreateTexture1DBind();
|
||||
}
|
||||
|
||||
Texture1D *CreateTexture1D(Texture1DData *ptr)
|
||||
{
|
||||
Texture1D *tex=CreateTexture1D();
|
||||
|
||||
if(!tex)RETURN_ERROR_NULL;
|
||||
|
||||
tex->SetImage(ptr);
|
||||
return(tex);
|
||||
}
|
||||
|
||||
Texture1D *CreateTexture1D(uint length, TSF format)
|
||||
{
|
||||
Texture1D *tex = CreateTexture1D();
|
||||
|
||||
if (!tex)RETURN_ERROR_NULL;
|
||||
|
||||
tex->SetImage(length,format);
|
||||
return(tex);
|
||||
}
|
||||
|
||||
Texture1D *CreateTexture1D(uint length, void *bitmap, uint bitmap_bytes, TSF source_format, uint video_format)
|
||||
{
|
||||
Texture1D *tex = CreateTexture1D();
|
||||
|
||||
if (!tex)RETURN_ERROR_NULL;
|
||||
|
||||
tex->SetImage(length, bitmap,bitmap_bytes,source_format, video_format);
|
||||
return(tex);
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
98
src/RenderDriver/Texture1DDSA.cpp
Normal file
98
src/RenderDriver/Texture1DDSA.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
#include<hgl/graph/Texture1D.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Texture1DDSA:public Texture1D
|
||||
{
|
||||
public:
|
||||
|
||||
using Texture1D::Texture1D;
|
||||
|
||||
bool _SetImage(Texture1DData *tex) override
|
||||
{
|
||||
glTextureStorage1D(texture_id, 1, tex->video_format, tex->length);
|
||||
|
||||
if(!tex->bitmap)
|
||||
return(true);
|
||||
|
||||
if(tex->source_format->compress) //原本就是压缩格式
|
||||
glCompressedTextureSubImage1D(texture_id, 0, 0, tex->length, tex->video_format, tex->bitmap_bytes, tex->bitmap);
|
||||
else //正常非压缩格式
|
||||
glTextureSubImage1D(texture_id, 0, 0, tex->length, tex->source_format->pixel_format, tex->source_format->data_type, tex->bitmap);
|
||||
|
||||
if(tex->gen_mipmaps)
|
||||
{
|
||||
glGenerateTextureMipmap(texture_id);
|
||||
|
||||
// glTexEnvf(GL_TEXTURE_FILTER_CONTROL,GL_TEXTURE_LOD_BIAS,-1.5f); //设置LOD偏向,负是更精细,正是更模糊
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
int _GetImage(void *data_pointer, TSF fmt, int level) override
|
||||
{
|
||||
int compress;
|
||||
int bytes;
|
||||
|
||||
const TextureFormat *tsf = TextureFormatInfoList + fmt;
|
||||
|
||||
glGetTextureLevelParameteriv(texture_id, level, GL_TEXTURE_COMPRESSED, &compress);
|
||||
|
||||
if (compress)
|
||||
{
|
||||
glGetTextureLevelParameteriv(texture_id, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &bytes);
|
||||
|
||||
if (data_pointer)
|
||||
glGetCompressedTextureImage(texture_id, level, bytes, data_pointer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tsf->video_bytes == 0)return(-1);
|
||||
|
||||
bytes = length*tsf->video_bytes;
|
||||
|
||||
if (data_pointer)
|
||||
glGetTextureImage(texture_id, level, tsf->pixel_format, tsf->data_type, bytes, data_pointer);
|
||||
}
|
||||
|
||||
return(bytes);
|
||||
}
|
||||
|
||||
bool _ChangeImage(uint s, uint l, void *data, uint bytes, TSF sf) override
|
||||
{
|
||||
const TextureFormat *sfmt = TextureFormatInfoList + sf; //原始数据格式
|
||||
|
||||
if (sfmt->compress)
|
||||
glCompressedTextureSubImage1D(texture_id, 0, s, l, sfmt->video_format, bytes, data);
|
||||
else
|
||||
glTextureSubImage1D(texture_id, 0, s, l, sfmt->pixel_format, sfmt->data_type, data);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void GenMipmaps() override
|
||||
{
|
||||
glGenerateTextureMipmap(texture_id);
|
||||
}
|
||||
|
||||
void GetMipmapLevel(int &base_level,int &max_level) override
|
||||
{
|
||||
glGetTextureParameteriv(texture_id,GL_TEXTURE_BASE_LEVEL,&base_level);
|
||||
glGetTextureParameteriv(texture_id,GL_TEXTURE_MAX_LEVEL,&max_level);
|
||||
}
|
||||
};//class Texture1DDSA:public Texture1D
|
||||
|
||||
Texture1D *CreateTexture1DDSA()
|
||||
{
|
||||
uint id;
|
||||
|
||||
glCreateTextures(GL_TEXTURE_1D,1,&id);
|
||||
|
||||
return(new Texture1DDSA(id));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
126
src/RenderDriver/Texture2D.cpp
Normal file
126
src/RenderDriver/Texture2D.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
#include<hgl/graph/Texture2D.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
//#include<hgl/graph/Bitmap.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
bool Texture2D::SetImage(Texture2DData *ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("param error,ptr=nullptr"));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (!ptr->width || !ptr->height)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("size error,width=") + OSString(ptr->width) + OS_TEXT(",height=") + OSString(ptr->height));
|
||||
return(false);
|
||||
}
|
||||
|
||||
width = ptr->width;
|
||||
height = ptr->height;
|
||||
|
||||
video_format = ptr->GetVideoFormat();
|
||||
pixel_format = ptr->GetPixelFormat();
|
||||
|
||||
if (!_SetImage(ptr))
|
||||
{
|
||||
width=height= 0;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
int Texture2D::GetImage(void *data_pointer, TSF fmt, int level)
|
||||
{
|
||||
if (!TextureSourceFormatCheck(fmt))
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("glTexture2D::GetImage,fmt error =") + OSString(fmt));
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return _GetImage(data_pointer,fmt,level,width,height);
|
||||
}
|
||||
|
||||
bool Texture2D::ChangeImage(uint l, uint t, uint w, uint h, void *data, uint bytes, TSF sf)
|
||||
{
|
||||
if (l>width || t>height
|
||||
|| w>width - l
|
||||
|| h>height - t
|
||||
|| !data
|
||||
|| !TextureSourceFormatCheck(sf))
|
||||
RETURN_FALSE;
|
||||
|
||||
return _ChangeImage(l,t,w,h, data, bytes, sf);
|
||||
}
|
||||
}//namespace graph
|
||||
|
||||
namespace graph
|
||||
{
|
||||
Texture2D *CreateTexture2DDSA();
|
||||
Texture2D *CreateTexture2DBind();
|
||||
|
||||
Texture2D *CreateTexture2D()
|
||||
{
|
||||
// if(GLEW_VERSION_4_5||GLEW_ARB_direct_state_access||GL_EXT_direct_state_access)
|
||||
return CreateTexture2DDSA();
|
||||
// else
|
||||
// return CreateTexture2DBind();
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2D(Texture2DData *ptr)
|
||||
{
|
||||
Texture2D *tex = CreateTexture2D();
|
||||
|
||||
if (!tex)RETURN_ERROR_NULL;
|
||||
|
||||
tex->SetImage(ptr);
|
||||
return(tex);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2D(uint width, uint height, TSF format)
|
||||
{
|
||||
Texture2D *tex = CreateTexture2D();
|
||||
|
||||
if (!tex)RETURN_ERROR_NULL;
|
||||
|
||||
tex->SetImage(width,height,format);
|
||||
return(tex);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2D(uint width, uint height, void *bitmap, uint bitmap_bytes, TSF source_format, uint video_format)
|
||||
{
|
||||
Texture2D *tex = CreateTexture2D();
|
||||
|
||||
if (!tex)RETURN_ERROR_NULL;
|
||||
|
||||
tex->SetImage(width,height, bitmap, bitmap_bytes, source_format, video_format);
|
||||
return(tex);
|
||||
}
|
||||
|
||||
// Texture2D *CreateTexture2D(const OSString &filename,uint video_format)
|
||||
// {
|
||||
// Texture2D *tex = CreateTexture2D();
|
||||
//
|
||||
// if (!tex)RETURN_ERROR_NULL;
|
||||
//
|
||||
// Bitmap2D bmp;
|
||||
//
|
||||
// if(!LoadBitmapFromFile(&bmp,filename))
|
||||
// RETURN_ERROR_NULL;
|
||||
//
|
||||
// tex->SetImage(bmp.GetWidth(),
|
||||
// bmp.GetHeight(),
|
||||
// bmp.GetData(),
|
||||
// bmp.GetDataLength(),
|
||||
// bmp.GetFormat(),
|
||||
// video_format);
|
||||
//
|
||||
// return(tex);
|
||||
// }
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
98
src/RenderDriver/Texture2DDSA.cpp
Normal file
98
src/RenderDriver/Texture2DDSA.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
#include<hgl/graph/Texture2D.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Texture2DDSA:public Texture2D
|
||||
{
|
||||
public:
|
||||
|
||||
using Texture2D::Texture2D;
|
||||
|
||||
bool _SetImage(Texture2DData *tex) override
|
||||
{
|
||||
glTextureStorage2D(texture_id, 1, tex->video_format, tex->width, tex->height);
|
||||
|
||||
if(!tex->bitmap)
|
||||
return(true);
|
||||
|
||||
if(tex->source_format->compress) //原本就是压缩格式
|
||||
glCompressedTextureSubImage2D(texture_id, 0, 0, 0, tex->width, tex->height, tex->video_format, tex->bitmap_bytes, tex->bitmap);
|
||||
else //正常非压缩格式
|
||||
glTextureSubImage2D(texture_id, 0, 0, 0, tex->width, tex->height, tex->source_format->pixel_format, tex->source_format->data_type, tex->bitmap);
|
||||
|
||||
if(tex->gen_mipmaps)
|
||||
{
|
||||
glGenerateTextureMipmap(texture_id);
|
||||
|
||||
// glTexEnvf(GL_TEXTURE_FILTER_CONTROL,GL_TEXTURE_LOD_BIAS,-1.5f); //设置LOD偏向,负是更精细,正是更模糊
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
int _GetImage(void *data_pointer, TSF fmt, int level,int width,int height) override
|
||||
{
|
||||
int compress;
|
||||
int bytes;
|
||||
|
||||
const TextureFormat *tsf = TextureFormatInfoList + fmt;
|
||||
|
||||
glGetTextureLevelParameteriv(texture_id, level, GL_TEXTURE_COMPRESSED, &compress);
|
||||
|
||||
if (compress)
|
||||
{
|
||||
glGetTextureLevelParameteriv(texture_id, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &bytes);
|
||||
|
||||
if (data_pointer)
|
||||
glGetCompressedTextureImage(texture_id, level, bytes, data_pointer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tsf->video_bytes == 0)return(-1);
|
||||
|
||||
bytes = width*height*tsf->video_bytes;
|
||||
|
||||
if (data_pointer)
|
||||
glGetTextureImage(texture_id, level, tsf->pixel_format, tsf->data_type, bytes, data_pointer);
|
||||
}
|
||||
|
||||
return(bytes);
|
||||
}
|
||||
|
||||
bool _ChangeImage(uint l, uint t, uint w, uint h, void *data, uint bytes, TSF sf) override
|
||||
{
|
||||
const TextureFormat *sfmt = TextureFormatInfoList + sf; //原始数据格式
|
||||
|
||||
if (sfmt->compress)
|
||||
glCompressedTextureSubImage2D(texture_id, 0, l, t, w, h, sfmt->video_format, bytes, data);
|
||||
else
|
||||
glTextureSubImage2D(texture_id, 0, l, t, w, h, sfmt->pixel_format, sfmt->data_type, data);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void GenMipmaps() override
|
||||
{
|
||||
glGenerateTextureMipmap(texture_id);
|
||||
}
|
||||
|
||||
void GetMipmapLevel(int &base_level,int &max_level) override
|
||||
{
|
||||
glGetTextureParameteriv(texture_id,GL_TEXTURE_BASE_LEVEL,&base_level);
|
||||
glGetTextureParameteriv(texture_id,GL_TEXTURE_MAX_LEVEL,&max_level);
|
||||
}
|
||||
};//class Texture2DDSA
|
||||
|
||||
Texture2D *CreateTexture2DDSA()
|
||||
{
|
||||
uint id;
|
||||
|
||||
glCreateTextures(GL_TEXTURE_2D,1,&id);
|
||||
|
||||
return(new Texture2DDSA(id));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
137
src/RenderDriver/TextureFormat.cpp
Normal file
137
src/RenderDriver/TextureFormat.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
#include<hgl/graph/TextureFormat.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
//贴图数据源格式
|
||||
const TextureFormat TextureFormatInfoList[]=
|
||||
{
|
||||
{HGL_SF_NONE, "", false, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE ,0,0},
|
||||
|
||||
{HGL_SF_R8, "R8", false, 0, GL_R8, GL_RED, GL_UNSIGNED_BYTE ,1,1},
|
||||
{HGL_SF_RG8, "RG8", false, 0, GL_RG8, GL_RG, GL_UNSIGNED_BYTE ,2,2},
|
||||
{HGL_SF_RGB8, "RGB8", false, 0, GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ,3,3},
|
||||
{HGL_SF_RGBA8, "RGBA8", false, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ,4,4},
|
||||
|
||||
{HGL_SF_SRGB8, "SRGB8", false, 0, GL_SRGB8, GL_SRGB, GL_UNSIGNED_BYTE ,4,4},
|
||||
{HGL_SF_SRGBA8, "SRGBA8", false, 0, GL_SRGB8_ALPHA8, GL_SRGB_ALPHA, GL_UNSIGNED_BYTE ,5,5},
|
||||
|
||||
{HGL_SF_R16, "R16", false, 0, GL_R16, GL_RED, GL_UNSIGNED_SHORT ,2,2},
|
||||
{HGL_SF_RG16, "RG16", false, 0, GL_RG16, GL_RG, GL_UNSIGNED_SHORT ,4,4},
|
||||
{HGL_SF_RGB16, "RGB16", false, 0, GL_RGB16, GL_RGB, GL_UNSIGNED_SHORT ,6,6},
|
||||
{HGL_SF_RGBA16, "RGBA16", false, 0, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT ,8,8},
|
||||
|
||||
{HGL_SF_R16F, "R16F", false, 0, GL_R16F, GL_RED, GL_FLOAT ,2,2},
|
||||
{HGL_SF_RG16F, "RG16F", false, 0, GL_RG16F, GL_RG, GL_FLOAT ,4,4},
|
||||
{HGL_SF_RGB16F, "RGB16F", false, 0, GL_RGB16F, GL_RGB, GL_FLOAT ,6,6},
|
||||
{HGL_SF_RGBA16F, "RGBA16F", false, 0, GL_RGBA16F, GL_RGBA, GL_FLOAT ,8,8},
|
||||
|
||||
{HGL_SF_R32F, "R32F", false, 0, GL_R32F, GL_RED, GL_FLOAT ,4,4},
|
||||
{HGL_SF_RG32F, "RG32F", false, 0, GL_RG32F, GL_RG, GL_FLOAT ,8,8},
|
||||
{HGL_SF_RGB32F, "RGB32F", false, 0, GL_RGB32F, GL_RGB, GL_FLOAT ,12,12},
|
||||
{HGL_SF_RGBA32F, "RGBA32F", false, 0, GL_RGBA32F, GL_RGBA, GL_FLOAT ,16,16},
|
||||
|
||||
{HGL_SF_UNCOMPRESSED, "", false, 0, 0, 0, 0 ,0,0},
|
||||
|
||||
{HGL_SF_R3_G3_B2, "R3_G3_B2", false, 0, GL_R3_G3_B2, GL_RGB, GL_UNSIGNED_BYTE_3_3_2 ,1,1},
|
||||
{HGL_SF_RGB565, "RGB565", false, 0, GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ,2,2},
|
||||
|
||||
{HGL_SF_RGBA4, "RGBA4", false, 0, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ,2,2},
|
||||
{HGL_SF_RGB5_A1, "RGB5_A1", false, 0, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ,2,2},
|
||||
{HGL_SF_RGB10_A2, "RGB10_A2", false, 0, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_10_10_10_2 ,4,4},
|
||||
|
||||
{HGL_SF_RG11F_B10F, "RG11F_B10F", false, 0, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ,4,4},
|
||||
{HGL_SF_RGB9_E5, "RGB9_E5", false, 0, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ,4,4},
|
||||
|
||||
{HGL_SF_DEPTH, "", false, 0, 0, 0, 0 ,0,0},
|
||||
|
||||
{HGL_SF_DEPTH16, "DEPTH16", false, 0, GL_DEPTH_COMPONENT16, GL_DEPTH, GL_UNSIGNED_SHORT ,2,2},
|
||||
{HGL_SF_DEPTH24, "DEPTH24", false, 0, GL_DEPTH_COMPONENT24, GL_DEPTH, GL_UNSIGNED_BYTE ,3,3},
|
||||
{HGL_SF_DEPTH32, "DEPTH32", false, 0, GL_DEPTH_COMPONENT32, GL_DEPTH, GL_UNSIGNED_INT ,4,4},
|
||||
|
||||
{HGL_SF_DEPTH32F, "DEPTH32F", false, 0, GL_DEPTH_COMPONENT32F, GL_DEPTH, GL_FLOAT ,4,4},
|
||||
|
||||
{HGL_SF_INDEX, "", false, 0, 0, 0, 0 ,0,0},
|
||||
|
||||
{HGL_SF_INDEX_16_RGB, "16RGB", false, 16, GL_LUMINANCE4, GL_RGB, GL_UNSIGNED_BYTE ,0,0},
|
||||
{HGL_SF_INDEX_16_RGBA, "16RGBA", false, 16, GL_LUMINANCE4, GL_RGBA, GL_UNSIGNED_BYTE ,0,0},
|
||||
{HGL_SF_INDEX_256_RGB, "256RGB", false, 256,GL_LUMINANCE8, GL_RGB, GL_UNSIGNED_BYTE ,0,0},
|
||||
{HGL_SF_INDEX_256_RGBA, "256RGBA", false, 256,GL_LUMINANCE8, GL_RGBA, GL_UNSIGNED_BYTE ,0,0},
|
||||
|
||||
{HGL_SF_COMPRESSED, "", false, 0, 0, 0, 0 ,0,0},
|
||||
/*
|
||||
{HGL_SF_CR, "CR", true, 0, GL_COMPRESSED_RED, GL_RED, 0,0,0}, //注:GL_COMPRESSED RED/RG/RGB/RGBA/SRGB/SRGBA这6个格式
|
||||
{HGL_SF_CRG, "CRG", true, 0, GL_COMPRESSED_RG, GL_RG, 0,0,0}, //只能用于glTexImage,由于显卡并不一定确定最终用什么算法,
|
||||
{HGL_SF_CRGB, "CRGB", true, 0, GL_COMPRESSED_RGB, GL_RGB, 0,0,0}, //所以用glGetCompressTexImage取出的数据,不能在glCompressTexImage中用
|
||||
{HGL_SF_CRGBA, "CRGBA", true, 0, GL_COMPRESSED_RGBA, GL_RGBA, 0,0,0},
|
||||
|
||||
{HGL_SF_CSRGB, "CSRGB", true, 0, GL_COMPRESSED_SRGB, GL_SRGB, 0,0,0},
|
||||
{HGL_SF_CSRGBA, "CSRGBA", true, 0, GL_COMPRESSED_SRGB_ALPHA, GL_SRGB_ALPHA, 0,0,0},
|
||||
*/
|
||||
{HGL_SF_DXT1RGB, "DXT1RGB", true, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, 0,0,0},
|
||||
{HGL_SF_DXT1RGBA, "DXT1RGBA", true, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, 0,0,0},
|
||||
{HGL_SF_DXT3RGBA, "DXT3RGBA", true, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, 0,0,0},
|
||||
{HGL_SF_DXT5RGBA, "DXT5RGBA", true, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, 0,0,0},
|
||||
|
||||
{HGL_SF_LATC1, "LATC1", true, 0, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_RED, 0,0,0},
|
||||
{HGL_SF_LATC1s, "LATC1s", true, 0, GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT, GL_RED, 0,0,0},
|
||||
{HGL_SF_LATC2, "LATC2", true, 0, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_RG, 0,0,0},
|
||||
{HGL_SF_LATC2s, "LATC2s", true, 0, GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT, GL_RG, 0,0,0},
|
||||
|
||||
{HGL_SF_RGTC1, "RGTC1", true, 0, GL_COMPRESSED_RED_RGTC1, GL_RED, 0,0,0},
|
||||
{HGL_SF_RGTC1s, "RGTC1s", true, 0, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_RED, 0,0,0},
|
||||
{HGL_SF_RGTC2, "RGTC2", true, 0, GL_COMPRESSED_RG_RGTC2, GL_RG, 0,0,0},
|
||||
{HGL_SF_RGTC2s, "RGTC2s", true, 0, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_RG, 0,0,0},
|
||||
|
||||
{HGL_SF_BPTC_RGBf, "BPTC_RGBf", true, 0, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, GL_RGB, 0,0,0},
|
||||
{HGL_SF_BPTC_RGBuf, "BPTC_RGBuf", true, 0, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, GL_RGB, 0,0,0},
|
||||
{HGL_SF_BPTC_RGBA, "BPTC_RGBA", true, 0, GL_COMPRESSED_RGBA_BPTC_UNORM, GL_RGBA, 0,0,0},
|
||||
{HGL_SF_BPTC_SRGBA, "BPTC_SRGBA", true, 0, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, GL_SRGB_ALPHA, 0,0,0},
|
||||
|
||||
{HGL_SF_ETC2_RGB8, "ETC2_RGB8", true, 0, GL_COMPRESSED_RGB8_ETC2, GL_RGB, 0,0,0},
|
||||
{HGL_SF_ETC2_SRGB8, "ETC2_SRGB8", true, 0, GL_COMPRESSED_SRGB8_ETC2, GL_SRGB, 0,0,0},
|
||||
{HGL_SF_ETC2_RGB8A1, "ETC2_RGB8A1", true, 0, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_RGBA, 0,0,0},
|
||||
{HGL_SF_ETC2_SRGB8A1, "ETC2_SRGB8A1", true, 0, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_SRGB_ALPHA, 0,0,0},
|
||||
{HGL_SF_ETC2_RGBA8, "ETC2_RGBA8", true, 0, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_RGBA, 0,0,0},
|
||||
{HGL_SF_ETC2_SRGBA8, "ETC2_SRGBA8", true, 0, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_SRGB_ALPHA, 0,0,0},
|
||||
|
||||
{HGL_SF_EAC_R11, "EAC_R11", true, 0, GL_COMPRESSED_R11_EAC, GL_RED, 0,0,0},
|
||||
{HGL_SF_EAC_R11s, "EAC_R11s", true, 0, GL_COMPRESSED_SIGNED_R11_EAC, GL_RED, 0,0,0},
|
||||
{HGL_SF_EAC_RG11, "EAC_RG11", true, 0, GL_COMPRESSED_RG11_EAC, GL_RG, 0,0,0},
|
||||
{HGL_SF_EAC_RG11s, "EAC_RG11s", true, 0, GL_COMPRESSED_SIGNED_RG11_EAC, GL_RG, 0,0,0}
|
||||
};//const TextureFormat TextureFormatInfoList[]
|
||||
|
||||
const int TextureFormatCount=sizeof(TextureFormatInfoList)/sizeof(TextureFormat);
|
||||
|
||||
bool TextureSourceFormatCheck(const TextureSourceFormat &tsf)
|
||||
{
|
||||
if(tsf<=HGL_SF_NONE
|
||||
||tsf>=HGL_SF_END
|
||||
||tsf==HGL_SF_UNCOMPRESSED
|
||||
||tsf==HGL_SF_INDEX
|
||||
||tsf==HGL_SF_COMPRESSED)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool TextureSourceFormatDepthCheck(const TextureSourceFormat &tsf)
|
||||
{
|
||||
return (tsf>HGL_SF_DEPTH&&tsf<HGL_SF_INDEX);
|
||||
}
|
||||
|
||||
TSF GetTextureFormatEnum(const char *str)
|
||||
{
|
||||
char fmt[17];
|
||||
|
||||
memcpy(fmt,str,16);
|
||||
fmt[16]=0;
|
||||
|
||||
for(int i=0;i<TextureFormatCount;i++)
|
||||
if(::strcmp(fmt,TextureFormatInfoList[i].name)==0)
|
||||
return(TextureFormatInfoList[i].tsf);
|
||||
|
||||
return(HGL_SF_NONE);
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user