File indexing completed on 2025-01-18 10:04:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _OpenGl_TextureFormat_HeaderFile
0015 #define _OpenGl_TextureFormat_HeaderFile
0016
0017 #include <Image_CompressedFormat.hxx>
0018 #include <Image_Format.hxx>
0019 #include <OpenGl_GlCore13.hxx>
0020 #include <TCollection_AsciiString.hxx>
0021
0022 class OpenGl_Context;
0023
0024
0025 class OpenGl_TextureFormat
0026 {
0027 public:
0028
0029
0030
0031
0032 template<class theCompType, int theNbComps>
0033 static OpenGl_TextureFormat Create();
0034
0035
0036
0037
0038
0039
0040 Standard_EXPORT static OpenGl_TextureFormat FindFormat (const Handle(OpenGl_Context)& theCtx,
0041 Image_Format theFormat,
0042 bool theIsColorMap);
0043
0044
0045
0046
0047
0048 Standard_EXPORT static OpenGl_TextureFormat FindSizedFormat (const Handle(OpenGl_Context)& theCtx,
0049 GLint theSizedFormat);
0050
0051
0052
0053
0054
0055 Standard_EXPORT static OpenGl_TextureFormat FindCompressedFormat (const Handle(OpenGl_Context)& theCtx,
0056 Image_CompressedFormat theFormat,
0057 bool theIsColorMap);
0058
0059
0060 Standard_EXPORT static TCollection_AsciiString FormatFormat (GLint theInternalFormat);
0061
0062
0063 Standard_EXPORT static TCollection_AsciiString FormatDataType (GLint theDataType);
0064
0065 public:
0066
0067
0068 OpenGl_TextureFormat() : myImageFormat (Image_Format_UNKNOWN), myInternalFormat (0), myPixelFormat (0), myDataType (0), myNbComponents (0) {}
0069
0070
0071 bool IsValid() const
0072 {
0073 return myInternalFormat != 0
0074 && myPixelFormat != 0
0075 && myDataType != 0;
0076 }
0077
0078
0079 GLint InternalFormat() const { return myInternalFormat; }
0080
0081
0082 void SetInternalFormat (GLint theInternal) { myInternalFormat = theInternal; }
0083
0084
0085 GLenum PixelFormat() const { return myPixelFormat; }
0086
0087
0088 void SetPixelFormat (GLenum theFormat) { myPixelFormat = theFormat; }
0089
0090
0091 GLint DataType() const { return myDataType; }
0092
0093
0094 void SetDataType (GLint theType) { myDataType = theType; }
0095
0096
0097 GLint NbComponents() const { return myNbComponents; }
0098
0099
0100 void SetNbComponents (GLint theNbComponents) { myNbComponents = theNbComponents; }
0101
0102
0103 bool IsSRGB() const
0104 {
0105 return myInternalFormat == GL_SRGB8
0106 || myInternalFormat == GL_SRGB8_ALPHA8;
0107 }
0108
0109
0110 Image_Format ImageFormat() const { return myImageFormat; }
0111
0112
0113 void SetImageFormat (Image_Format theFormat) { myImageFormat = theFormat; }
0114
0115 public:
0116
0117
0118 GLint Internal() const { return myInternalFormat; }
0119
0120
0121 GLenum Format() const { return myPixelFormat; }
0122
0123 private:
0124
0125 Image_Format myImageFormat;
0126 GLint myInternalFormat;
0127 GLenum myPixelFormat;
0128 GLint myDataType;
0129 GLint myNbComponents;
0130
0131 };
0132
0133
0134 template<class T> struct OpenGl_TextureFormatSelector
0135 {
0136
0137 };
0138
0139
0140 template<> struct OpenGl_TextureFormatSelector<GLubyte>
0141 {
0142 static GLint DataType() { return GL_UNSIGNED_BYTE; }
0143 static GLint Internal (GLuint theChannels)
0144 {
0145 switch (theChannels)
0146 {
0147 case 1: return GL_R8;
0148 case 2: return GL_RG8;
0149 case 3: return GL_RGB8;
0150 case 4: return GL_RGBA8;
0151 default: return GL_NONE;
0152 }
0153 }
0154 };
0155
0156
0157 template<> struct OpenGl_TextureFormatSelector<GLushort>
0158 {
0159 static GLint DataType() { return GL_UNSIGNED_SHORT; }
0160 static GLint Internal (GLuint theChannels)
0161 {
0162 switch (theChannels)
0163 {
0164 case 1: return GL_R16;
0165 case 2: return GL_RG16;
0166 case 3: return GL_RGB16;
0167 case 4: return GL_RGBA16;
0168 default: return GL_NONE;
0169 }
0170 }
0171 };
0172
0173
0174 template<> struct OpenGl_TextureFormatSelector<GLfloat>
0175 {
0176 static GLint DataType() { return GL_FLOAT; }
0177 static GLint Internal (GLuint theChannels)
0178 {
0179 switch (theChannels)
0180 {
0181 case 1: return GL_R32F;
0182 case 2: return GL_RG32F;
0183 case 3: return GL_RGB32F;
0184 case 4: return GL_RGBA32F;
0185 default: return GL_NONE;
0186 }
0187 }
0188 };
0189
0190
0191 template<> struct OpenGl_TextureFormatSelector<GLuint>
0192 {
0193 static GLint DataType() { return GL_UNSIGNED_INT; }
0194 static GLint Internal (GLuint theChannels)
0195 {
0196 switch (theChannels)
0197 {
0198 case 1: return GL_RED;
0199 case 2: return GL_RG;
0200 case 3: return GL_RGB;
0201 case 4: return GL_RGBA;
0202 default: return GL_NONE;
0203 }
0204 }
0205 };
0206
0207
0208 template<> struct OpenGl_TextureFormatSelector<GLbyte>
0209 {
0210 static GLint DataType() { return GL_BYTE; }
0211 static GLint Internal (GLuint theChannels)
0212 {
0213 switch (theChannels)
0214 {
0215 case 1: return GL_R8_SNORM;
0216 case 2: return GL_RG8_SNORM;
0217 case 3: return GL_RGB8_SNORM;
0218 case 4: return GL_RGBA8_SNORM;
0219 default: return GL_NONE;
0220 }
0221 }
0222 };
0223
0224
0225 template<> struct OpenGl_TextureFormatSelector<GLshort>
0226 {
0227 static GLint DataType() { return GL_SHORT; }
0228 static GLint Internal (GLuint theChannels)
0229 {
0230 switch (theChannels)
0231 {
0232 case 1: return GL_R16_SNORM;
0233 case 2: return GL_RG16_SNORM;
0234 case 3: return GL_RGB16_SNORM;
0235 case 4: return GL_RGBA16_SNORM;
0236 default: return GL_NONE;
0237 }
0238 }
0239 };
0240
0241
0242 template<> struct OpenGl_TextureFormatSelector<GLint>
0243 {
0244 static GLint DataType() { return GL_INT; }
0245 static GLint Internal (GLuint theChannels)
0246 {
0247 switch (theChannels)
0248 {
0249 case 1: return GL_RED_SNORM;
0250 case 2: return GL_RG_SNORM;
0251 case 3: return GL_RGB_SNORM;
0252 case 4: return GL_RGBA_SNORM;
0253 default: return GL_NONE;
0254 }
0255 }
0256 };
0257
0258
0259
0260
0261
0262 template<class theCompType, int theNbComps>
0263 inline OpenGl_TextureFormat OpenGl_TextureFormat::Create()
0264 {
0265 OpenGl_TextureFormat aFormat;
0266 aFormat.SetNbComponents (theNbComps);
0267 aFormat.SetInternalFormat (OpenGl_TextureFormatSelector<theCompType>::Internal (theNbComps));
0268 aFormat.SetDataType (OpenGl_TextureFormatSelector<theCompType>::DataType());
0269 GLenum aPixelFormat = GL_NONE;
0270 switch (theNbComps)
0271 {
0272 case 1: aPixelFormat = GL_RED; break;
0273 case 2: aPixelFormat = GL_RG; break;
0274 case 3: aPixelFormat = GL_RGB; break;
0275 case 4: aPixelFormat = GL_RGBA; break;
0276 }
0277 aFormat.SetPixelFormat (aPixelFormat);
0278 return aFormat;
0279 }
0280
0281 #endif